@@ -70,6 +70,24 @@ interface ApiReferenceQueryResult {
70
70
} ;
71
71
}
72
72
73
+ interface MdxEdge {
74
+ node : {
75
+ id : string ;
76
+ frontmatter : {
77
+ slug : string ;
78
+ } ;
79
+ internal : {
80
+ contentFilePath : string ;
81
+ } ;
82
+ } ;
83
+ }
84
+
85
+ interface MdxQueryResult {
86
+ allMdx : {
87
+ edges : MdxEdge [ ] ;
88
+ } ;
89
+ }
90
+
73
91
export const createPages : GatsbyNode [ 'createPages' ] = async ( { graphql, actions : { createPage, createRedirect } } ) => {
74
92
/**
75
93
* It's not ideal to have:
@@ -104,6 +122,25 @@ export const createPages: GatsbyNode['createPages'] = async ({ graphql, actions:
104
122
}
105
123
}
106
124
` ) ;
125
+
126
+ const mdxResult = await graphql < MdxQueryResult > ( `
127
+ query {
128
+ allMdx {
129
+ edges {
130
+ node {
131
+ id
132
+ frontmatter {
133
+ slug
134
+ }
135
+ internal {
136
+ contentFilePath
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+ ` ) ;
143
+
107
144
/**
108
145
* We could log here, the reason we don't right now is that the error should already have been caught and logged.
109
146
* Because Gatsby spawns a bunch of async processes during the onCreateNode step, though, and errors don't prevent
@@ -207,6 +244,26 @@ export const createPages: GatsbyNode['createPages'] = async ({ graphql, actions:
207
244
return slug ;
208
245
} ;
209
246
247
+ const mdxCreator = async ( edge : MdxEdge ) : Promise < string > => {
248
+ const slug = edge . node . frontmatter . slug ;
249
+
250
+ if ( ! slug ) {
251
+ return slug ;
252
+ }
253
+
254
+ createPage ( {
255
+ path : slug ,
256
+ component : edge . node . internal . contentFilePath ,
257
+ context : {
258
+ slug,
259
+ mdx : true ,
260
+ layout : { sidebar : true , searchBar : true , template : 'base' } ,
261
+ } ,
262
+ } ) ;
263
+
264
+ return slug ;
265
+ } ;
266
+
210
267
createRedirect ( {
211
268
fromPath : '/' ,
212
269
toPath : '/docs' ,
@@ -233,5 +290,6 @@ export const createPages: GatsbyNode['createPages'] = async ({ graphql, actions:
233
290
await Promise . all ( [
234
291
...documentResult . data . allFileHtml . edges . map ( documentCreator ( documentTemplate ) ) ,
235
292
...apiReferenceResult . data . allFileHtml . edges . map ( documentCreator ( apiReferenceTemplate ) ) ,
293
+ ...( mdxResult . data ?. allMdx . edges . map ( mdxCreator ) ?? [ ] ) ,
236
294
] ) ;
237
295
} ;
0 commit comments