@@ -9,6 +9,15 @@ const fmtURI = (uri, isSlugify) =>
9
9
exports . createPages = async function ( { actions, graphql } ) {
10
10
const { data } = await graphql ( `
11
11
query {
12
+ file(base: { eq: "rgd.json" }) {
13
+ childrenDiscussionsJson {
14
+ website {
15
+ description
16
+ home
17
+ title
18
+ }
19
+ }
20
+ }
12
21
allDiscussionsJson {
13
22
edges {
14
23
previous {
@@ -36,9 +45,10 @@ exports.createPages = async function ({ actions, graphql }) {
36
45
labels {
37
46
edges {
38
47
node {
39
- color
40
- name
41
48
id
49
+ name
50
+ color
51
+ description
42
52
}
43
53
}
44
54
}
@@ -49,16 +59,20 @@ exports.createPages = async function ({ actions, graphql }) {
49
59
}
50
60
` ) ;
51
61
62
+ const websiteData = data ?. file ?. childrenDiscussionsJson ?. [ 0 ] ?. website ;
63
+
52
64
let categoryMap = new Map ( ) ;
53
65
let labelsMap = new Map ( ) ;
66
+ let labelsColorMap = { } ;
54
67
let nlen = 0 ;
55
68
56
69
data ?. allDiscussionsJson ?. edges ?. forEach ( ( { previous, next, node } ) => {
70
+ if ( ! node ) return ;
57
71
const curr = node . node ;
58
- const number = curr . number ;
72
+ const number = curr ? .number ;
59
73
60
74
// number length
61
- const _nlen = `${ number } ` . length ;
75
+ const _nlen = `${ number || 0 } ` . length ;
62
76
if ( nlen < _nlen ) nlen = _nlen ;
63
77
64
78
// create issues pages
@@ -80,6 +94,7 @@ exports.createPages = async function ({ actions, graphql }) {
80
94
labels . forEach ( ( label ) => {
81
95
if ( ! labelsMap . get ( label . node . name ) ) {
82
96
labelsMap . set ( label . node . name , label . node ) ;
97
+ labelsColorMap [ label . node . name ] = label . node . color ;
83
98
}
84
99
} ) ;
85
100
} ) ;
@@ -115,6 +130,26 @@ exports.createPages = async function ({ actions, graphql }) {
115
130
component : require . resolve ( `./src/templates/nav-labels.tsx` ) ,
116
131
context : { labelsList : Array . from ( labelsMap . values ( ) ) } ,
117
132
} ) ;
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
+ }
118
153
} ;
119
154
120
155
// Fix warn chunk commons [mini-css-extract-plugin] error in Gatsby JS
@@ -129,70 +164,112 @@ exports.onCreateWebpackConfig = ({ actions }) => {
129
164
} ) ;
130
165
} ;
131
166
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 } ) => {
133
188
const { createTypes } = actions ;
134
- const typeDefs = `
135
- type DiscussionsJsonNode {
189
+ const typeDefs = [
190
+ ` type DiscussionsJsonNode {
136
191
category: Category
137
192
labels: LabelsConnection
138
- }
139
-
140
- type Category {
193
+ }` ,
194
+ `type Category {
141
195
name: String!
142
196
emoji: String!
143
197
description: String!
144
198
isAnswerable: Boolean!
145
- }
146
-
147
- type LabelsConnection {
199
+ }` ,
200
+ `type LabelsConnection {
148
201
edges: [LabelsEdge]
149
- }
150
- type LabelsEdge {
202
+ }` ,
203
+ ` type LabelsEdge {
151
204
node: Labels
152
- }
153
- type Labels {
205
+ }` ,
206
+ ` type Labels {
154
207
id: String
155
208
name: String
156
209
color: String
157
- }
158
-
159
- type IssuesJson implements Node {
210
+ description: String
211
+ }` ,
212
+ ` type IssuesJson implements Node {
160
213
labels: LabelsConnection
161
214
author: Author
162
215
comments: CommentsConnection
163
216
category: Category
164
217
upvoteCount: Int
165
- }
166
-
167
- type CommentsConnection {
218
+ }` ,
219
+ `type CommentsConnection {
168
220
edges: [CommentsEdge]
169
- }
170
- type CommentsEdge {
221
+ }` ,
222
+ ` type CommentsEdge {
171
223
node: IssuesJsonCommentsEdgesNode
172
- }
173
-
174
- type IssuesJsonCommentsEdgesNode {
224
+ }` ,
225
+ `type IssuesJsonCommentsEdgesNode {
175
226
id: String!
176
227
bodyHTML: String!
177
228
author: Author!
178
229
replies: RepliesConnection
179
- }
180
- type RepliesConnection {
230
+ }` ,
231
+ ` type RepliesConnection {
181
232
edges: [RepliesEdge]
182
- }
183
- type RepliesEdge {
233
+ }` ,
234
+ ` type RepliesEdge {
184
235
node: Replies
185
- }
186
- type Replies {
236
+ }` ,
237
+ ` type Replies {
187
238
id: String!
188
239
bodyHTML: String!
189
240
author: Author!
190
- }
191
- type Author {
241
+ }` ,
242
+ ` type Author {
192
243
login: String!
193
244
avatarUrl: String!
194
245
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
+ ] ;
197
274
createTypes ( typeDefs ) ;
198
275
} ;
0 commit comments