text: const path = require("path")
  
  module.exports.onCreateNode = ({ node, actions }) => {
    const { createNodeField } = actions
    if (node.internal.type === "MarkdownRemark") {
      const slug = path.basename(node.fileAbsolutePath, ".md")
      createNodeField({
        node,
        name: "slug",
        value: slug,
      })
    }
  }
  
  module.exports.createPages = async ({ graphql, actions }) => {
    const { createPage } = actions
    const blogTemplate = path.resolve("./src/templates/blog-template.js")
    const res = await graphql(`
      query {
        allMarkdownRemark(
          sort: { fields: [frontmatter___date], order: DESC }
          limit: 1000
        ) {
          edges {
            node {
              fields {
                slug
              }
              frontmatter {
                title
              }
            }
          }
        }
      }
    `)
  
    // Create blog posts pages
    // Note: posts are in descending order
    const posts = res.data.allMarkdownRemark.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({
        component: blogTemplate,
        path: `/blog/${post.node.fields.slug}`,
        context: {
          slug: post.node.fields.slug,
          previous,
          next,
        },
      })
    })
  }
  