text: const path = require(`path`);
  const { createFilePath } = require(`gatsby-source-filesystem`);
  
  exports.createPages = async ({ graphql, actions }) => {
    const { createPage } = actions;
  
    const blogPost = path.resolve(`./src/templates/blog-post.js`);
    const tagTemplate = path.resolve(`src/templates/tags.js`);
    const result = await graphql(
      `
        {
          postsGroup: allMdx(
            filter: { fileAbsolutePath: { regex: "/content/blog/" } }
            sort: { fields: [frontmatter___date], order: DESC }
            limit: 1000
          ) {
            edges {
              node {
                fields {
                  slug
                }
                frontmatter {
                  title
                }
              }
            }
          }
          tagsGroup: allMdx(
            filter: { fileAbsolutePath: { regex: "/content/blog/" } }
            limit: 2000
          ) {
            group(field: frontmatter___tags) {
              fieldValue
            }
          }
        }
      `,
    );
  
    if (result.errors) {
      throw result.errors;
    }
  
    const posts = result.data.postsGroup.edges;
    const tags = result.data.tagsGroup.group;
  
    // Create post pages
    posts.forEach((post, index) => {
      const previous = index === posts.length - 1 ? null : posts[index + 1].node;
      const next = index === 0 ? null : posts[index - 1].node;
  
      createPage({
        path: `/blog${post.node.fields.slug}`,
        component: blogPost,
        context: {
          slug: post.node.fields.slug,
          previous,
          next,
        },
      });
    });
  
    // Create tag pages
    tags.forEach(tag => {
      createPage({
        path: `/tags/${tag.fieldValue}/`,
        component: tagTemplate,
        context: {
          tag: tag.fieldValue,
        },
      });
    });
  
    return null;
  };
  
  exports.onCreateNode = ({ node, actions, getNode }) => {
    const { createNodeField } = actions;
  
    if (node.internal.type === `Mdx`) {
      const value = createFilePath({ node, getNode });
      createNodeField({
        name: `slug`,
        node,
        value,
      });
    }
  };
  
  exports.onCreateWebpackConfig = ({ actions }) => {
    actions.setWebpackConfig({
      resolve: {
        modules: [path.resolve(__dirname, 'src'), 'node_modules'],
      },
    });
  };
  