text: const { createFilePath } = require('gatsby-source-filesystem');
  const path = require('path');
  
  const onCreateNode = ({ node, actions, getNode }) => {
    const { createNodeField } = actions;
  
    if (node.internal.type === 'MarkdownRemark') {
      const value = createFilePath({ node, getNode });
  
      createNodeField({
        name: 'slug',
        node,
        value,
      });
    }
  };
  
  const createPages = async ({ actions, graphql, reporter }) => {
    const { createPage } = actions;
    const result = await graphql(`
      {
        allMarkdownRemark {
          edges {
            node {
              fields {
                slug
              }
              frontmatter {
                templateKey
              }
            }
          }
        }
      }
    `);
  
    if (result.errors) {
      reporter.panicOnBuild(`Error while running GraphQL query.`);
      return;
    }
  
    result.data.allMarkdownRemark.edges.forEach(({ node }) => {
      createPage({
        path: node.fields.slug,
        component: path.resolve(
          `src/templates/${String(node.frontmatter.templateKey)}.js`
        ),
        context: {
          slug: node.fields.slug,
        },
      });
    });
  };
  
  module.exports = {
    onCreateNode,
    createPages,
  };
  