text: const path = require(`path`)
  const {
    createFilePath
  } = require(`gatsby-source-filesystem`)
  
  exports.createPages = ({
    graphql,
    actions
  }) => {
    const {
      createPage
    } = actions
  
    const blogPostTemplate = path.resolve(`./src/templates/blog-post.js`)
  
    return graphql(
      `
        {
          allMarkdownRemark(
            sort: { fields: [frontmatter___date], order: DESC }
            limit: 1000
          ) {
            edges {
              node {
                fields {
                  slug
                }
                frontmatter {
                  title
                  category
                }
              }
            }
          }
        }
      `
    ).then(result => {
      if (result.errors) {
        throw result.errors
      }
  
      // Create blog posts pages.
      const posts = result.data.allMarkdownRemark.edges.filter(
        ({
          node
        }) => !!node.frontmatter.category
      )
  
      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: post.node.fields.slug,
          component: blogPostTemplate,
          context: {
            slug: post.node.fields.slug,
            previous,
            next,
          },
        })
      })
    })
  }
  
  exports.onCreateNode = ({
    node,
    actions,
    getNode
  }) => {
    const {
      createNodeField
    } = actions
  
    if (node.internal.type === `MarkdownRemark`) {
      const value = createFilePath({
        node,
        getNode
      })
  
      console.log(value)
  
      createNodeField({
        name: `slug`,
        node,
        value,
      })
    }
  }
  