text: /**
   * Implement Gatsby's Node APIs in this file.
   *
   * See: https://www.gatsbyjs.org/docs/node-apis/
   */
  
  // You can delete this file if you're not using it
  const path = require(`path`)
  const _ = require("lodash")
  const { createFilePath } = require(`gatsby-source-filesystem`)
  
  
  exports.onCreateNode = ({ node, getNode, actions }) => {
    const { createNodeField } = actions
    if (node.internal.type === `MarkdownRemark`) {
      const slug = createFilePath({ node, getNode })
  
      createNodeField({
        node,
        name: `slug`,
        value: slug
      })
    }
  }
  
  exports.createPages = async ({ graphql, actions }) => {
    const { createPage } = actions
    const result = await graphql(`
      {
       allMarkdownRemark {
          edges {
            node {
              fields {
                slug
              }
              frontmatter {
                categories
              }
            }
          }
        }
        categoriesGroup: allMarkdownRemark(limit: 2000) {
          group(field: frontmatter___categories) {
            fieldValue
          }
        }
      }
      `)
    result.data.allMarkdownRemark.edges.forEach(({ node }) => {
      createPage({
        path: node.fields.slug,
        component: path.resolve(`./src/templates/post.js`),
        context: {
          slug: node.fields.slug
        }
      })
    })
  
    const categories = result.data.categoriesGroup.group
  
    categories.forEach(category => {
      createPage({
        path: `/categories/${(categories.fieldValue)}/`,
        component: path.resolve(`./src/templates/chapters.js`),
        context: {
          category: category.fieldValue,
        },
      })
    })
  }
  