Skip to content

Commit

Permalink
chore: add discussions2
Browse files Browse the repository at this point in the history
  • Loading branch information
lencx committed Apr 12, 2022
1 parent 3785461 commit 1e8fc88
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
2 changes: 2 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ exports.createSchemaCustomization = ({ actions, schema }) => {
'repo',
'issues_owner',
'issues_repo',
'dis_owner',
'dis_repo',
'cname',
'type',
]),
Expand Down
16 changes: 11 additions & 5 deletions src/components/issues_num/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ interface IssuesNumProps {

const IssuesNum: FC<IssuesNumProps> = (props) => {
const rgdData = useRgd();
const isIssue = rgdData.type === 'issues';

let _link;
if (isIssue) {
_link = `https://github.com/${rgdData.issues_owner}/${rgdData.issues_repo}/issues/${props.number}`;
} else {
_link = `https://github.com/${rgdData.owner}/${rgdData.repo}/discussions/${props.number}`;
switch (rgdData.type) {
case 'issues':
_link = `https://github.com/${rgdData.issues_owner}/${rgdData.issues_repo}/issues/${props.number}`;
break;
case 'discussions2':
_link = `https://github.com/${rgdData.dis_owner}/${rgdData.dis_repo}/discussions/${props.number}`;
break;
default:
_link = `https://github.com/${rgdData.owner}/${rgdData.repo}/discussions/${props.number}`;
}

return (
<a
className={clsx('number issues-num', props.className)}
Expand Down
34 changes: 23 additions & 11 deletions src/hooks/useRepoLink.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import useRgd from './useRgd';

export default function useRepoLink() {
const { type, owner, repo, issues_owner, issues_repo, cname } = useRgd();
const { type, owner, repo, issues_owner, issues_repo, dis_owner, dis_repo, cname } = useRgd();

let repoLink, repoType, dataRepo, repoTxt;
const siteRepo = `https://github.com/${owner}/${repo}`;
let rssLink = '/feed.xml';
if (type === 'issues') {
dataRepo = `https://github.com/${issues_owner}/${issues_repo}`;
repoLink = `${dataRepo}/issues`;
repoType = 'issues';
repoTxt = `${issues_owner}/${issues_repo}`;
} else {
dataRepo = siteRepo;
repoLink = `${dataRepo}/discussions`;
repoType = 'discussions';
repoTxt = `${owner}/${repo}`;

switch (type) {
case 'issues': {
dataRepo = `https://github.com/${issues_owner}/${issues_repo}`;
repoLink = `${dataRepo}/issues`;
repoType = 'issues';
repoTxt = `${issues_owner}/${issues_repo}`;
break;
}
case 'discussions2': {
dataRepo = `https://github.com/${dis_owner}/${dis_repo}`;
repoLink = `${dataRepo}/discussions`;
repoType = 'discussions';
repoTxt = `${dis_owner}/${dis_repo}`;
break;
}
default: {
dataRepo = siteRepo;
repoLink = `${dataRepo}/discussions`;
repoType = 'discussions';
repoTxt = `${owner}/${repo}`;
}
}

if (!/\.github\.io$/.test(repo) && !cname) {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useRgd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default function useRgd() {
cname
issues_owner
issues_repo
dis_owner
dis_repo
website {
title
description
Expand Down

0 comments on commit 1e8fc88

Please sign in to comment.