text: const { createFilePath } = require(`gatsby-source-filesystem`)
  const path = require(`path`)
  
  
  exports.onCreateNode = ({ node, getNode, actions }) => {
    const { createNodeField } = actions
  
    if (node.internal.type === `MarkdownRemark`) {
      const fileNode = getNode(node.parent)
      if (fileNode.relativePath.startsWith("categories")) {
        const slug = getNode(node.parent).name
  
        createNodeField({
          node,
          name: `slug`,
          value: slug,
        })
      }
    }
  }
  
  exports.createPages = async ({ graphql, actions }) => {
    const { createPage } = actions
  
    // **Note:** The graphql function call returns a Promise
    // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise for more info
    const result = await graphql(`
      query {
        allMarkdownRemark {
          edges {
            node {
              fields {
                slug
              }
            }
          }
        }
      }
    `)
    result.data.allMarkdownRemark.edges.forEach(({ node }) => {
      if (!node.fields) return;
      createPage({
        path: node.fields.slug,
        component: path.resolve(`./src/templates/categories.tsx`),
        context: {
          // Data passed to context is available
          // in page queries as GraphQL variables.
          slug: node.fields.slug,
        },
      })
    })
  }
  