@@ -3,66 +3,50 @@ const { createFilePath } = require('gatsby-source-filesystem')
33
44exports . onCreateNode = ( { node, actions, getNode } ) => {
55 const { createNodeField } = actions
6-
7- // you only want to operate on `Mdx` nodes. If you had content from a
8- // remote CMS you could also check to see if the parent node was a
9- // `File` node here
106 if ( node . internal . type === 'Mdx' ) {
11- const value = createFilePath ( { node, getNode } )
7+ const slug = createFilePath ( { node, getNode } )
128
139 createNodeField ( {
14- // Name of the field you are adding
1510 name : 'slug' ,
16- // Individual MDX node
1711 node,
18- // Generated value based on filepath with "blog" prefix. you
19- // don't need a separating "/" before the value because
20- // createFilePath returns a path with the leading "/".
21- value : `${ value } ` ,
12+ value : `${ slug } ` ,
2213 } )
2314 }
2415}
2516
2617exports . createPages = async ( { graphql, actions, reporter } ) => {
27- // Destructure the createPage function from the actions object
2818 const { createPage, createRedirect } = actions
2919 const result = await graphql ( `
3020 query {
3121 allMdx {
32- edges {
33- node {
34- id
35- fields {
36- slug
37- }
38- tableOfContents(maxDepth: 10)
39- internal {
40- contentFilePath
41- }
22+ nodes {
23+ id
24+ fields {
25+ slug
26+ }
27+ internal {
28+ contentFilePath
4229 }
30+ tableOfContents(maxDepth: 3)
4331 }
4432 }
4533 }
4634 ` )
35+
4736 if ( result . errors ) {
48- reporter . panicOnBuild ( '🚨 ERROR: Loading "createPages" query' )
37+ reporter . panicOnBuild ( 'Error loading MDX result' , result . errors )
4938 }
50- // Create blog post pages.
51- const posts = result . data . allMdx . edges
52- const docsTemplate = path . resolve ( `./src/templates/Docs.tsx` )
53- // you'll call `createPage` for each result
54- posts . forEach ( ( { node } , index ) => {
55- ! node . internal . contentFilePath . includes ( 'api' ) &&
56- createPage ( {
57- // This is the slug you created before
58- // (or `node.frontmatter.slug`)
59- path : node . fields . slug ,
60- // This component will wrap our MDX content
61- component : `${ docsTemplate } ?__contentFilePath=${ node . internal . contentFilePath } ` ,
62- // You can use the values in this context in
63- // our page layout component
64- context : { id : node . id } ,
65- } )
39+
40+ const posts = result . data . allMdx . nodes
41+
42+ posts . forEach ( ( node ) => {
43+ createPage ( {
44+ path : node . fields . slug ,
45+ component : `${ path . resolve ( `./src/templates/MdxLayout.tsx` ) } ?__contentFilePath=${
46+ node . internal . contentFilePath
47+ } `,
48+ context : { id : node . id } ,
49+ } )
6650 } )
6751 createRedirect ( {
6852 fromPath : `/` ,
0 commit comments