text: const path = require(`path`);
  const { createFilePath } = require(`gatsby-source-filesystem`);
  
  exports.createPages = ({ graphql, actions }) => {
    const { createPage } = actions;
  
    const blogPost = path.resolve(`./src/templates/blog-post.tsx`);
    return graphql(
      `
        {
          allMdx(
            filter: { fileAbsolutePath: { regex: "/blog/.*.md$/" } }
            sort: { fields: [frontmatter___date], order: DESC }
            limit: 1000
          ) {
            edges {
              node {
                fields {
                  slug
                  readingTime {
                    text
                  }
                }
                frontmatter {
                  title
                }
              }
            }
          }
        }
      `
    )
      .then(result => {
        if (result.errors) {
          throw result.errors;
        }
  
        // Create blog posts pages.
        const posts = result.data.allMdx.edges;
  
        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,
            },
          });
        });
  
        return null;
      })
      .catch(err => {
        console.error(err);
      });
  };
  
  exports.onCreateNode = ({ node, actions, getNode }) => {
    const { createNodeField } = actions;
  
    if (node.internal.type === `Mdx`) {
      const value = createFilePath({ node, getNode });
      createNodeField({
        name: `slug`,
        node,
        value,
      });
    }
  };
  