Skip to content

Commit a5586ea

Browse files
committed
chore: add issues
1 parent f888eb9 commit a5586ea

File tree

12 files changed

+1465
-1384
lines changed

12 files changed

+1465
-1384
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717
with:
1818
node-version: '14'
1919
- run: yarn
20-
- run: yarn posts --token=${{ secrets.GH_TOKEN }} --owner=${{ secrets.GG_USER }} --repo=${{ secrets.GG_REPO }}
20+
- run: yarn posts --token=${{ secrets.GG_TOKEN }} --owner=${{ secrets.GG_USER }} --repo=${{ secrets.GG_REPO }}
2121
- run: yarn reconf
2222
- run: yarn build
2323
- run: yarn copy
2424

2525
- name: Deploy
2626
uses: peaceiris/actions-gh-pages@v3
2727
with:
28-
github_token: ${{ secrets.GH_TOKEN }}
28+
github_token: ${{ secrets.GG_TOKEN }}
2929
publish_dir: ./public
3030
force_orphan: true

gatsby-config.bak.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
repo: `https://github.com/lencx/gg`,
88
rss: `/feed.xml`,
99
userLogo: false,
10+
type: 'discussions',
1011
},
1112
plugins: [
1213
`gatsby-plugin-sass`,

gatsby-node.js

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ exports.createPages = async function ({ actions, graphql }) {
5353
let labelsMap = new Map();
5454
let nlen = 0;
5555

56-
data.allDiscussionsJson.edges.forEach(({ previous, next, node }) => {
56+
data?.allDiscussionsJson?.edges?.forEach(({ previous, next, node }) => {
5757
const curr = node.node;
5858
const number = curr.number;
5959

@@ -69,18 +69,19 @@ exports.createPages = async function ({ actions, graphql }) {
6969
});
7070

7171
// category
72-
const category = curr.category;
73-
if (!categoryMap.get(category.name)) {
74-
categoryMap.set(category.name, category);
72+
const category = curr?.category;
73+
if (category && !categoryMap.get(category?.name)) {
74+
categoryMap.set(category?.name, category);
7575
}
7676

7777
// labels
78-
const labels = curr.labels.edges;
79-
labels.forEach((label) => {
80-
if (!labelsMap.get(label.node.name)) {
81-
labelsMap.set(label.node.name, label.node);
82-
}
83-
});
78+
const labels = curr?.labels?.edges;
79+
labels &&
80+
labels.forEach((label) => {
81+
if (!labelsMap.get(label.node.name)) {
82+
labelsMap.set(label.node.name, label.node);
83+
}
84+
});
8485
});
8586

8687
// create category pages
@@ -127,3 +128,69 @@ exports.onCreateWebpackConfig = ({ actions }) => {
127128
],
128129
});
129130
};
131+
132+
exports.createSchemaCustomization = ({ actions }) => {
133+
const { createTypes } = actions;
134+
const typeDefs = `
135+
type DiscussionsJsonNode {
136+
category: Category
137+
labels: LabelsConnection
138+
}
139+
140+
type Category {
141+
name: String!
142+
emoji: String!
143+
description: String!
144+
isAnswerable: Boolean!
145+
}
146+
147+
type LabelsConnection {
148+
edges: [LabelsEdge]
149+
}
150+
type LabelsEdge {
151+
node: Labels!
152+
}
153+
type Labels {
154+
id: String
155+
name: String
156+
color: String
157+
}
158+
159+
type IssuesJson implements Node {
160+
labels: LabelsConnection
161+
author: Author!
162+
comments: CommentsConnection
163+
}
164+
165+
type CommentsConnection {
166+
edges: [CommentsEdge]
167+
}
168+
type CommentsEdge {
169+
node: IssuesJsonCommentsEdgesNode
170+
}
171+
172+
type IssuesJsonCommentsEdgesNode {
173+
id: String!
174+
bodyHTML: String!
175+
author: Author!
176+
replies: RepliesConnection
177+
}
178+
type RepliesConnection {
179+
edges: [RepliesEdge]
180+
}
181+
type RepliesEdge {
182+
node: Replies!
183+
}
184+
type Replies {
185+
id: String!
186+
bodyHTML: String!
187+
author: Author!
188+
}
189+
type Author {
190+
login: String!
191+
avatarUrl: String!
192+
url: String!
193+
}
194+
`;
195+
createTypes(typeDefs);
196+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@
5050
},
5151
"devDependencies": {
5252
"@types/body-scroll-lock": "^3.1.0",
53-
"rgd": "^1.2.3"
53+
"rgd": "^2.0.0"
5454
}
5555
}

scripts/reconf.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ async function gatsbyConfUpdate() {
6868
conf.siteMetadata.title = rgdConf.title;
6969
conf.siteMetadata.description = rgdConf.description;
7070
conf.siteMetadata.owner = rgdConf.owner;
71+
conf.siteMetadata.type = rgdConf.type;
7172
conf.siteMetadata.repo = `https://github.com/${rgdConf.owner}/${rgdConf.repo}`;
7273

7374
// download logo
@@ -86,7 +87,11 @@ async function gatsbyConfUpdate() {
8687
function pkgUpdate() {
8788
pkg.name = rgdConf.repo;
8889
pkg.description = rgdConf.description;
89-
pkg.scripts.posts = `rgd --owner=${rgdConf.owner} --repo=${rgdConf.repo} --mode=json,rss --jsonfmt=true --outdir=discussions`;
90+
let issuesInfo = '';
91+
if (rgdConf['issues-owner'] && rgdConf['issues-repo']) {
92+
issuesInfo = ` --issues-owner=${rgdConf['issues-owner']} --issues-repo=${rgdConf['issues-repo']}`;
93+
}
94+
pkg.scripts.posts = `rgd --owner=${rgdConf.owner} --repo=${rgdConf.repo} --mode=json,rss --jsonfmt=true --outdir=discussions${issuesInfo}`;
9095

9196
fs.writeFile('package.json', JSON.stringify(pkg, null, 2), function (err) {
9297
if (err) return;

src/components/category/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { FC } from 'react';
2-
import { Link } from 'gatsby';
2+
import { Link, navigate } from 'gatsby';
33

44
import getEmoji from '@utils/emoji';
55
import { fmtURI } from '@utils/tools';
@@ -12,6 +12,7 @@ interface CategoryProps {
1212
}
1313

1414
const Category: FC<CategoryProps> = ({ data, go }) => {
15+
if (!(data && data?.name)) return null;
1516
return (
1617
<Link
1718
className="gg-category"

src/components/nav/NavScreen.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ const NavScreen: FC<NavScreenProps> = ({ isHide, siteMetadata }) => {
2020
<div className={clsx('nav-screen', { open: isHide })}>
2121
<div>
2222
<nav>
23-
<li onClick={() => navigate(`/category`)}>
24-
<Icon
25-
className="icon-action"
26-
icon={iconCategory}
27-
fontSize="20"
28-
color="var(--gg-icon)"
29-
/>
30-
Category
31-
</li>
23+
{siteMetadata.type !== 'issues' && (
24+
<li onClick={() => navigate(`/category`)}>
25+
<Icon
26+
className="icon-action"
27+
icon={iconCategory}
28+
fontSize="20"
29+
color="var(--gg-icon)"
30+
/>
31+
Category
32+
</li>
33+
)}
3234
<li onClick={() => navigate(`/labels`)}>
3335
<Icon
3436
className="icon-action"

src/styles/base.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ body {
6565
.text-center {
6666
text-align: center;
6767
}
68+
69+
.gg-empty {
70+
font-size: 18px;
71+
color: rgba(180, 180, 180, 0.5);
72+
}

src/styles/issues.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
margin-bottom: 20px;
2323
}
2424

25+
.gg-label {
26+
margin: 5px;
27+
}
28+
2529
.ques-content {
2630
display: flex;
2731
margin-top: 5px;

src/templates/issues.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ export default function BlogIssues(props: any) {
8080
!isHide &&
8181
comments?.[0]?.node?.author?.login &&
8282
comments.map(({ node }: any) => {
83-
const _replies = node.replies.edges;
83+
const _replies = node?.replies?.edges;
8484
return (
8585
<div className="comments-item" key={node.id}>
8686
<Author author={node.author} />
8787
<div
8888
className="comments-item-content"
8989
dangerouslySetInnerHTML={{ __html: node.bodyHTML }}
9090
/>
91-
{_replies.map(({ node: node2 }: any) => {
91+
{_replies?.map(({ node: node2 }: any) => {
9292
return (
9393
<div className="comments-item" key={node2.id}>
9494
<Author author={node2.author} />

0 commit comments

Comments
 (0)