Skip to content

Commit d15acfc

Browse files
committed
chore: label category
1 parent c5e4f30 commit d15acfc

32 files changed

+833
-240
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
with:
1818
node-version: '14'
1919
- run: yarn
20-
- run: yarn posts --token=${{ secrets.GG_TOKEN }} --owner=${{ secrets.GG_USER }} --repo=${{ secrets.GG_REPO }} --issues-owner=${{ secrets.GG_ISSUES_USER }} --issues-repo=${{ secrets.GG_ISSUES_REPO }} --type=${{ secrets.GG_TYPE }}
20+
- run: yarn posts:ci --token=${{ secrets.GG_TOKEN }}
2121
- run: yarn reconf
2222
- run: yarn build
2323
- run: yarn copy

gatsby-config.bak.js

Lines changed: 0 additions & 65 deletions
This file was deleted.

gatsby-config.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,53 @@
1-
module.exports = require('./gatsby-config.bak');
1+
const ggConfig = require('./gg.config.json');
2+
3+
module.exports = {
4+
pathPrefix: ggConfig.pathPrefix,
5+
siteMetadata: {
6+
userLogo: ggConfig.siteMetadata.userLogo,
7+
},
8+
plugins: [
9+
`gatsby-plugin-sass`,
10+
`gatsby-transformer-json`,
11+
{
12+
resolve: `gatsby-source-filesystem`,
13+
options: {
14+
name: `discussions`,
15+
path: `${__dirname}/discussions`,
16+
ignore: [
17+
// `${__dirname}/discussions/rgd.json`,
18+
`${__dirname}/discussions/rgd.yml`,
19+
`${__dirname}/discussions/feed.xml`,
20+
],
21+
},
22+
},
23+
{
24+
resolve: `gatsby-plugin-alias-imports`,
25+
options: {
26+
alias: {
27+
'@src': 'src',
28+
'@comps': 'src/components',
29+
'@layouts': 'src/layouts',
30+
'@pages': 'src/pages',
31+
'@styles': 'src/styles',
32+
'@hooks': 'src/hooks',
33+
'@templates': 'src/templates',
34+
'@utils': 'src/utils',
35+
'@icons': 'src/icons',
36+
},
37+
extensions: ['js', 'jsx', 'ts', 'tsx'],
38+
},
39+
},
40+
{
41+
resolve: `gatsby-plugin-manifest`,
42+
options: ggConfig.manifest,
43+
},
44+
{
45+
resolve: `gatsby-plugin-offline`,
46+
options: {
47+
workboxConfig: {
48+
importWorkboxFrom: `cdn`,
49+
},
50+
},
51+
},
52+
],
53+
};

gatsby-node.js

Lines changed: 115 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ const fmtURI = (uri, isSlugify) =>
99
exports.createPages = async function ({ actions, graphql }) {
1010
const { data } = await graphql(`
1111
query {
12+
file(base: { eq: "rgd.json" }) {
13+
childrenDiscussionsJson {
14+
website {
15+
description
16+
home
17+
title
18+
}
19+
}
20+
}
1221
allDiscussionsJson {
1322
edges {
1423
previous {
@@ -36,9 +45,10 @@ exports.createPages = async function ({ actions, graphql }) {
3645
labels {
3746
edges {
3847
node {
39-
color
40-
name
4148
id
49+
name
50+
color
51+
description
4252
}
4353
}
4454
}
@@ -49,16 +59,20 @@ exports.createPages = async function ({ actions, graphql }) {
4959
}
5060
`);
5161

62+
const websiteData = data?.file?.childrenDiscussionsJson?.[0]?.website;
63+
5264
let categoryMap = new Map();
5365
let labelsMap = new Map();
66+
let labelsColorMap = {};
5467
let nlen = 0;
5568

5669
data?.allDiscussionsJson?.edges?.forEach(({ previous, next, node }) => {
70+
if (!node) return;
5771
const curr = node.node;
58-
const number = curr.number;
72+
const number = curr?.number;
5973

6074
// number length
61-
const _nlen = `${number}`.length;
75+
const _nlen = `${number || 0}`.length;
6276
if (nlen < _nlen) nlen = _nlen;
6377

6478
// create issues pages
@@ -80,6 +94,7 @@ exports.createPages = async function ({ actions, graphql }) {
8094
labels.forEach((label) => {
8195
if (!labelsMap.get(label.node.name)) {
8296
labelsMap.set(label.node.name, label.node);
97+
labelsColorMap[label.node.name] = label.node.color;
8398
}
8499
});
85100
});
@@ -115,6 +130,26 @@ exports.createPages = async function ({ actions, graphql }) {
115130
component: require.resolve(`./src/templates/nav-labels.tsx`),
116131
context: { labelsList: Array.from(labelsMap.values()) },
117132
});
133+
134+
if (websiteData?.home === 'issues-labels') {
135+
// create home pages
136+
actions.createPage({
137+
path: `/`,
138+
component: require.resolve(`./src/templates/labels-category.tsx`),
139+
context: { colorMap: labelsColorMap },
140+
});
141+
// create archives pages
142+
actions.createPage({
143+
path: `/archives`,
144+
component: require.resolve(`./src/templates/archives.tsx`),
145+
});
146+
} else {
147+
// create home pages
148+
actions.createPage({
149+
path: `/`,
150+
component: require.resolve(`./src/templates/archives.tsx`),
151+
});
152+
}
118153
};
119154

120155
// Fix warn chunk commons [mini-css-extract-plugin] error in Gatsby JS
@@ -129,70 +164,112 @@ exports.onCreateWebpackConfig = ({ actions }) => {
129164
});
130165
};
131166

132-
exports.createSchemaCustomization = ({ actions }) => {
167+
const initFields = (fields) =>
168+
fields.reduce((a, b) => {
169+
let _type = 'String!';
170+
let _field = b;
171+
let _val = '';
172+
if (Array.isArray(b)) {
173+
_field = b[0];
174+
_type = b[1];
175+
if (b[1] === '[String]!') _val = [];
176+
if (b[1] === 'Boolean!') _val = false;
177+
}
178+
return {
179+
...a,
180+
[_field]: {
181+
type: _type,
182+
resolve: (v) => v[_field] || _val,
183+
},
184+
};
185+
}, {});
186+
187+
exports.createSchemaCustomization = ({ actions, schema }) => {
133188
const { createTypes } = actions;
134-
const typeDefs = `
135-
type DiscussionsJsonNode {
189+
const typeDefs = [
190+
`type DiscussionsJsonNode {
136191
category: Category
137192
labels: LabelsConnection
138-
}
139-
140-
type Category {
193+
}`,
194+
`type Category {
141195
name: String!
142196
emoji: String!
143197
description: String!
144198
isAnswerable: Boolean!
145-
}
146-
147-
type LabelsConnection {
199+
}`,
200+
`type LabelsConnection {
148201
edges: [LabelsEdge]
149-
}
150-
type LabelsEdge {
202+
}`,
203+
`type LabelsEdge {
151204
node: Labels
152-
}
153-
type Labels {
205+
}`,
206+
`type Labels {
154207
id: String
155208
name: String
156209
color: String
157-
}
158-
159-
type IssuesJson implements Node {
210+
description: String
211+
}`,
212+
`type IssuesJson implements Node {
160213
labels: LabelsConnection
161214
author: Author
162215
comments: CommentsConnection
163216
category: Category
164217
upvoteCount: Int
165-
}
166-
167-
type CommentsConnection {
218+
}`,
219+
`type CommentsConnection {
168220
edges: [CommentsEdge]
169-
}
170-
type CommentsEdge {
221+
}`,
222+
`type CommentsEdge {
171223
node: IssuesJsonCommentsEdgesNode
172-
}
173-
174-
type IssuesJsonCommentsEdgesNode {
224+
}`,
225+
`type IssuesJsonCommentsEdgesNode {
175226
id: String!
176227
bodyHTML: String!
177228
author: Author!
178229
replies: RepliesConnection
179-
}
180-
type RepliesConnection {
230+
}`,
231+
`type RepliesConnection {
181232
edges: [RepliesEdge]
182-
}
183-
type RepliesEdge {
233+
}`,
234+
`type RepliesEdge {
184235
node: Replies
185-
}
186-
type Replies {
236+
}`,
237+
`type Replies {
187238
id: String!
188239
bodyHTML: String!
189240
author: Author!
190-
}
191-
type Author {
241+
}`,
242+
`type Author {
192243
login: String!
193244
avatarUrl: String!
194245
url: String!
195-
}
196-
`;
246+
}`,
247+
schema.buildObjectType({
248+
name: 'DiscussionsJson',
249+
fields: {
250+
...initFields([
251+
'owner',
252+
'repo',
253+
'issues_owner',
254+
'issues_repo',
255+
'cname',
256+
'type',
257+
]),
258+
website: 'RgdWebsite',
259+
},
260+
interfaces: ['Node'],
261+
}),
262+
schema.buildObjectType({
263+
name: 'RgdWebsite',
264+
fields: initFields([
265+
'title',
266+
'description',
267+
'home',
268+
'built_date',
269+
['label_category', '[String]!'],
270+
['label_level', '[String]!'],
271+
]),
272+
}),
273+
];
197274
createTypes(typeDefs);
198275
};

gg.config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"pathPrefix": "/",
3+
"siteMetadata": {
4+
"userLogo": false
5+
},
6+
"manifest": {
7+
"name": "GG",
8+
"short_name": "GG",
9+
"start_url": "/",
10+
"background_color": "#fafafa",
11+
"theme_color": "#232629",
12+
"display": "standalone",
13+
"icon": "./src/static/pwa-logo.png"
14+
}
15+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"rgd": "rgd",
2121
"deploy": "node ./scripts/deploy",
2222
"posts": "rgd --mode=json,rss --jsonfmt=true --outdir=discussions",
23+
"posts:ci": "rgd",
2324
"reconf": "node ./scripts/reconf",
2425
"reset": "node ./scripts/reset",
2526
"copy": "node ./scripts/copy"
@@ -50,6 +51,6 @@
5051
},
5152
"devDependencies": {
5253
"@types/body-scroll-lock": "^3.1.0",
53-
"rgd": "^2.0.0"
54+
"rgd": "^2.0.2"
5455
}
5556
}

0 commit comments

Comments
 (0)