const path = require(`path`) exports.createPages = async ({ actions, graphql, reporter }) => { const { createPage } = actions const siteTemplate = path.resolve(`src/templates/siteTemplate.js`) const result = await graphql(` { allMdx(limit: 1000, filter: { fields: { source: { eq: "pages" } } }) { edges { node { frontmatter { path title edit } } } } } `) // Handle errors if (result.errors) { reporter.panicOnBuild(`Error while running GraphQL query.`) return } result.data.allMdx.edges.forEach(({ node }) => { createPage({ path: node.frontmatter.path, component: siteTemplate, context: {}, // additional data can be passed via context }) }) } exports.onCreateNode = ({ node, getNode, actions }) => { const { createNodeField } = actions if (node.internal.type === `Mdx`) { const value = getNode(node.parent).sourceInstanceName createNodeField({ node, name: `source`, value, }) } } exports.createSchemaCustomization = ({ actions }) => { const { createTypes } = actions const typeDefs = ` type Mdx implements Node { frontmatter: Frontmatter } type Frontmatter { edit: String } ` createTypes(typeDefs) }