1
1
const path = require ( "path" )
2
2
const sortLibs = require ( "./scripts/sort-libraries" )
3
- const globby = require ( ' globby' ) ;
4
- const frontmatterParser = require ( ' parser-front-matter' ) ;
5
- const { readFile } = require ( "fs-extra" ) ;
6
- const { promisify } = require ( ' util' ) ;
3
+ const globby = require ( " globby" )
4
+ const frontmatterParser = require ( " parser-front-matter" )
5
+ const { readFile } = require ( "fs-extra" )
6
+ const { promisify } = require ( " util" )
7
7
8
8
exports . onCreatePage = async ( { page, actions } ) => {
9
9
const { createPage, deletePage } = actions
@@ -13,59 +13,62 @@ exports.onCreatePage = async ({ page, actions }) => {
13
13
sourcePath : path . relative ( __dirname , page . componentPath ) ,
14
14
}
15
15
if ( page . path === "/code" || page . path === "/code/" ) {
16
- const markdownFilePaths = await globby ( ' src/content/code/**/*.md' ) ;
16
+ const markdownFilePaths = await globby ( " src/content/code/**/*.md" )
17
17
const codeData = { }
18
- const slugMap = require ( './src/content/code/slug-map.json' ) ;
19
- const parse$ = promisify ( frontmatterParser . parse ) ;
20
- await Promise . all ( markdownFilePaths . map ( async markdownFilePath => {
18
+ const slugMap = require ( "./src/content/code/slug-map.json" )
19
+ const parse$ = promisify ( frontmatterParser . parse )
20
+ await Promise . all (
21
+ markdownFilePaths . map ( async markdownFilePath => {
22
+ const markdownFileContent = await readFile ( markdownFilePath , "utf-8" )
23
+ let {
24
+ data : { name, description, url, github, npm, gem } ,
25
+ content : howto ,
26
+ } = await parse$ ( markdownFileContent , undefined )
27
+ howto = howto . trim ( )
28
+ const pathArr = markdownFilePath . split ( "/" )
29
+ if ( markdownFilePath . includes ( "language-support" ) ) {
30
+ const languageSupportDirIndex = pathArr . indexOf ( "language-support" )
31
+ const languageNameSlugIndex = languageSupportDirIndex + 1
32
+ const languageNameSlug = pathArr [ languageNameSlugIndex ]
33
+ const languageName = slugMap [ languageNameSlug ]
34
+ codeData . Languages = codeData . Languages || { }
35
+ codeData . Languages [ languageName ] =
36
+ codeData . Languages [ languageName ] || { }
21
37
22
- const markdownFileContent = await readFile ( markdownFilePath , "utf-8" )
23
- let {
24
- data : { name, description, url, github, npm, gem } ,
25
- content : howto ,
26
- } = await parse$ ( markdownFileContent , undefined )
27
- howto = howto . trim ( ) ;
28
- const pathArr = markdownFilePath . split ( "/" )
29
- if ( markdownFilePath . includes ( "language-support" ) ) {
30
- const languageSupportDirIndex = pathArr . indexOf ( "language-support" )
31
- const languageNameSlugIndex = languageSupportDirIndex + 1
32
- const languageNameSlug = pathArr [ languageNameSlugIndex ]
33
- const languageName = slugMap [ languageNameSlug ]
34
- codeData . Languages = codeData . Languages || { }
35
- codeData . Languages [ languageName ] = codeData . Languages [ languageName ] || { }
36
-
37
- const categoryNameSlugIndex = languageSupportDirIndex + 2
38
- const categoryNameSlug = pathArr [ categoryNameSlugIndex ]
39
- const categoryName = slugMap [ categoryNameSlug ]
40
- codeData . Languages [ languageName ] [ categoryName ] = codeData . Languages [ languageName ] [ categoryName ] || [ ]
41
- codeData . Languages [ languageName ] [ categoryName ] . push ( {
42
- name,
43
- description,
44
- howto,
45
- url,
46
- github,
47
- npm,
48
- gem,
49
- sourcePath : markdownFilePath ,
50
- } )
51
- } else {
52
- const codeDirIndex = pathArr . indexOf ( "code" )
53
- const categoryNameSlugIndex = codeDirIndex + 1
54
- const categoryNameSlug = pathArr [ categoryNameSlugIndex ]
55
- const categoryName = slugMap [ categoryNameSlug ]
56
- codeData [ categoryName ] = codeData [ categoryName ] || [ ]
57
- codeData [ categoryName ] . push ( {
58
- name,
59
- description,
60
- howto,
61
- url,
62
- github,
63
- npm,
64
- gem,
65
- sourcePath : markdownFilePath ,
66
- } )
67
- }
68
- } ) )
38
+ const categoryNameSlugIndex = languageSupportDirIndex + 2
39
+ const categoryNameSlug = pathArr [ categoryNameSlugIndex ]
40
+ const categoryName = slugMap [ categoryNameSlug ]
41
+ codeData . Languages [ languageName ] [ categoryName ] =
42
+ codeData . Languages [ languageName ] [ categoryName ] || [ ]
43
+ codeData . Languages [ languageName ] [ categoryName ] . push ( {
44
+ name,
45
+ description,
46
+ howto,
47
+ url,
48
+ github,
49
+ npm,
50
+ gem,
51
+ sourcePath : markdownFilePath ,
52
+ } )
53
+ } else {
54
+ const codeDirIndex = pathArr . indexOf ( "code" )
55
+ const categoryNameSlugIndex = codeDirIndex + 1
56
+ const categoryNameSlug = pathArr [ categoryNameSlugIndex ]
57
+ const categoryName = slugMap [ categoryNameSlug ]
58
+ codeData [ categoryName ] = codeData [ categoryName ] || [ ]
59
+ codeData [ categoryName ] . push ( {
60
+ name,
61
+ description,
62
+ howto,
63
+ url,
64
+ github,
65
+ npm,
66
+ gem,
67
+ sourcePath : markdownFilePath ,
68
+ } )
69
+ }
70
+ } )
71
+ )
69
72
const languageList = [ ]
70
73
let sortedTools = [ ]
71
74
await Promise . all ( [
@@ -139,11 +142,17 @@ exports.createPages = async ({ graphql, actions }) => {
139
142
sublinks
140
143
sidebarTitle
141
144
date
145
+ tags
142
146
}
143
147
id
144
148
}
145
149
}
146
150
}
151
+ tagsGroup: allMarkdownRemark {
152
+ group(field: frontmatter___tags) {
153
+ fieldValue
154
+ }
155
+ }
147
156
}
148
157
` )
149
158
@@ -177,13 +186,24 @@ exports.createPages = async ({ graphql, actions }) => {
177
186
// Note that this is mutated
178
187
let sideBardata = { }
179
188
180
-
181
189
// Sidebar items to add which don't come from markdown
182
190
const additionalSidebarItems = {
183
- foundation : [ {
184
- name : "GraphQL Foundation" ,
185
- links : [ { frontmatter : { sidebarTitle :"Foundation Members" , title : "Foundation Members" , permalink : "/foundation/members/" , date : null , category : "GraphQL Foundation" } } ]
186
- } ]
191
+ foundation : [
192
+ {
193
+ name : "GraphQL Foundation" ,
194
+ links : [
195
+ {
196
+ frontmatter : {
197
+ sidebarTitle : "Foundation Members" ,
198
+ title : "Foundation Members" ,
199
+ permalink : "/foundation/members/" ,
200
+ date : null ,
201
+ category : "GraphQL Foundation" ,
202
+ } ,
203
+ } ,
204
+ ] ,
205
+ } ,
206
+ ] ,
187
207
}
188
208
189
209
// E.g.
@@ -204,7 +224,10 @@ exports.createPages = async ({ graphql, actions }) => {
204
224
parent : { relativeDirectory, sourceInstanceName } ,
205
225
} = node
206
226
207
- if ( sourceInstanceName !== "content" || relativeDirectory . includes ( "code/" ) ) {
227
+ if (
228
+ sourceInstanceName !== "content" ||
229
+ relativeDirectory . includes ( "code/" )
230
+ ) {
208
231
return
209
232
}
210
233
@@ -216,13 +239,10 @@ exports.createPages = async ({ graphql, actions }) => {
216
239
} else {
217
240
pagesGroupedByFolder = {
218
241
...pagesGroupedByFolder ,
219
- [ relativeDirectory ] : [
220
- ...pagesGroupedByFolder [ relativeDirectory ] ,
221
- node ,
222
- ] ,
242
+ [ relativeDirectory ] : [ ...pagesGroupedByFolder [ relativeDirectory ] , node ] ,
223
243
}
224
244
}
225
-
245
+
226
246
allPages . push ( {
227
247
permalink,
228
248
relativeDirectory,
@@ -231,8 +251,8 @@ exports.createPages = async ({ graphql, actions }) => {
231
251
sourcePath : path . relative ( __dirname , node . fileAbsolutePath ) ,
232
252
} )
233
253
} )
234
-
235
- // Loop through the sections in the sidebar, mutating the
254
+
255
+ // Loop through the sections in the sidebar, mutating the
236
256
// next and previous objects for different
237
257
Object . entries ( pagesGroupedByFolder ) . map ( ( [ folder , pages ] ) => {
238
258
let pagesByUrl = { }
@@ -266,7 +286,7 @@ exports.createPages = async ({ graphql, actions }) => {
266
286
return
267
287
}
268
288
} )
269
-
289
+
270
290
if ( ! firstPage ) {
271
291
throw new Error ( `First page not found in ${ folder } ` )
272
292
}
@@ -309,18 +329,17 @@ exports.createPages = async ({ graphql, actions }) => {
309
329
categoriesMap [ currentCategory . name ] = currentCategory
310
330
}
311
331
312
- sideBardata [ folder ] = Object . values ( categoriesMap )
332
+ sideBardata [ folder ] = Object . values ( categoriesMap )
313
333
} )
314
334
315
335
Object . entries ( additionalSidebarItems ) . map ( ( [ folder , sections ] ) => {
316
336
sections . forEach ( s => {
317
337
const originalLinks = sideBardata [ folder ] . find ( l => l . name === s . name )
318
- originalLinks . links = [ ...originalLinks . links , ...s . links ]
338
+ originalLinks . links = [ ...originalLinks . links , ...s . links ]
319
339
} )
320
340
} )
321
341
322
-
323
- // Use all the set up data to now tell Gatsby to create pages
342
+ // Use all the set up data to now tell Gatsby to create pages
324
343
// on the site
325
344
allPages . forEach ( page => {
326
345
createPage ( {
@@ -334,4 +353,17 @@ exports.createPages = async ({ graphql, actions }) => {
334
353
} ,
335
354
} )
336
355
} )
356
+
357
+ // Create tag pages
358
+ const tagTemplate = path . resolve ( "src/templates/tags.tsx" )
359
+ const tags = result . data . tagsGroup . group
360
+ tags . forEach ( tag => {
361
+ createPage ( {
362
+ path : `/tags/${ tag . fieldValue } /` ,
363
+ component : tagTemplate ,
364
+ context : {
365
+ tag : tag . fieldValue ,
366
+ } ,
367
+ } )
368
+ } )
337
369
}
0 commit comments