1
- const path = require ( "node:path" )
2
- const sortLibs = require ( "./scripts/sort-libraries" )
3
- const globby = require ( "globby" )
4
- const frontmatterParser = require ( "parser-front-matter" )
5
- const { readFile } = require ( "node:fs/promises" )
6
- const { promisify } = require ( "node:util" )
1
+ import { GatsbyNode } from "gatsby"
2
+ import * as path from "path"
3
+ import { promisify } from "util"
4
+ import { readFile } from "fs/promises"
5
+ import * as globby from "globby"
6
+ import * as frontmatterParser from "parser-front-matter"
7
+ import { sortLibs } from "./scripts/sort-libraries"
7
8
8
9
const parse$ = promisify ( frontmatterParser . parse )
9
10
10
- exports . createSchemaCustomization = ( { actions } ) => {
11
- const gql = String . raw
12
- const { createTypes } = actions
13
-
14
- createTypes ( gql `
15
- type BlogPost implements Node @childOf(types: ["MarkdownRemark"]) {
16
- postId: String!
17
- title: String!
18
- tags: [String!]!
19
- date: Date! @dateformat(formatString: "YYYY-MM-DD")
20
- authors: [String!]!
21
- guestBio: String
22
- remark: MarkdownRemark! @link # backlink to the parent
23
- }
24
- ` )
25
- }
11
+ export const createSchemaCustomization : GatsbyNode [ "createSchemaCustomization" ] =
12
+ async ( { actions } ) => {
13
+ const gql = String . raw
14
+ const { createTypes } = actions
15
+
16
+ createTypes ( gql `
17
+ type BlogPost implements Node @childOf(types: ["MarkdownRemark"]) {
18
+ postId: String!
19
+ title: String!
20
+ tags: [String!]!
21
+ date: Date! @dateformat(formatString: "YYYY-MM-DD")
22
+ authors: [String!]!
23
+ guestBio: String
24
+ remark: MarkdownRemark! @link # backlink to the parent
25
+ }
26
+ ` )
27
+ }
26
28
27
29
// Transform nodes, each of logic inside here can be extracted to a separated plugin later.
28
- exports . onCreateNode = async ( {
30
+ export const onCreateNode : GatsbyNode [ "onCreateNode" ] = async ( {
29
31
reporter,
30
32
node,
31
33
actions,
@@ -79,7 +81,10 @@ exports.onCreateNode = async ({
79
81
}
80
82
}
81
83
82
- exports . onCreatePage = async ( { page, actions } ) => {
84
+ export const onCreatePage : GatsbyNode [ "onCreatePage" ] = async ( {
85
+ page,
86
+ actions,
87
+ } ) => {
83
88
// trying to refactor code to be "the Gatsby way".
84
89
// from the paths on ready, ignores a bunch of existing custom logic below.
85
90
if ( page . path . startsWith ( "/blog" ) ) {
@@ -93,11 +98,11 @@ exports.onCreatePage = async ({ page, actions }) => {
93
98
deletePage ( page )
94
99
let context = {
95
100
...page . context ,
96
- sourcePath : path . relative ( __dirname , page . componentPath ) ,
101
+ sourcePath : path . relative ( __dirname , page . path ) ,
97
102
}
98
103
if ( page . path === "/code" || page . path === "/code/" ) {
99
104
const markdownFilePaths = await globby ( "src/content/code/**/*.md" )
100
- const codeData = { }
105
+ const codeData : any = { }
101
106
const slugMap = require ( "./src/content/code/slug-map.json" )
102
107
await Promise . all (
103
108
markdownFilePaths . map ( async markdownFilePath => {
@@ -171,8 +176,8 @@ exports.onCreatePage = async ({ page, actions }) => {
171
176
}
172
177
} )
173
178
)
174
- const languageList = [ ]
175
- const toolList = [ ]
179
+ const languageList : any = [ ]
180
+ const toolList : any = [ ]
176
181
await Promise . all ( [
177
182
...Object . keys ( codeData . Languages ) . map ( async languageName => {
178
183
const libraryCategoryMap = codeData . Languages [ languageName ]
@@ -242,11 +247,14 @@ exports.onCreatePage = async ({ page, actions }) => {
242
247
} )
243
248
}
244
249
245
- exports . createPages = async ( { graphql, actions } ) => {
250
+ export const createPages : GatsbyNode [ "createPages" ] = async ( {
251
+ actions,
252
+ graphql,
253
+ } ) => {
246
254
const { createPage } = actions
247
255
248
256
const result = await graphql ( `
249
- {
257
+ query allMarkdownRemark {
250
258
allMarkdownRemark {
251
259
edges {
252
260
node {
@@ -493,12 +501,13 @@ exports.createPages = async ({ graphql, actions }) => {
493
501
}
494
502
}
495
503
496
- exports . onCreateWebpackConfig = ( { actions } ) => {
497
- actions . setWebpackConfig ( {
498
- resolve : {
499
- fallback : {
500
- assert : require . resolve ( "assert/" ) ,
504
+ export const onCreateWebpackConfig : GatsbyNode [ "onCreateWebpackConfig" ] =
505
+ async ( { actions } ) => {
506
+ actions . setWebpackConfig ( {
507
+ resolve : {
508
+ fallback : {
509
+ assert : "assert/" ,
510
+ } ,
501
511
} ,
502
- } ,
503
- } )
504
- }
512
+ } )
513
+ }
0 commit comments