text: /**
   * Implement Gatsby's Node APIs in this file.
   *
   * See: https://www.gatsbyjs.org/docs/node-apis/
   */
  const path = require(`path`)
  const { createFilePath } = require(`gatsby-source-filesystem`)
  
  exports.onCreateNode = ({ node, getNode, actions }) => {
    const { createNodeField } = actions
    if (node.internal.type === `MarkdownRemark`) {
      const slug = createFilePath({ node, getNode, basePath: `pages`, trailingSlash: false })
      createNodeField({ node, name: `slug`, value: slug })
    }
  }
  
  exports.createPages = ({ graphql, actions }) => {
    const { createPage } = actions
    return graphql(`
      {
        allMarkdownRemark {
          edges {
            node {
              fields {
                slug
              }
              frontmatter {
                type
              }
            }
          }
        }
      }
    `).then(result => {
      result.data.allMarkdownRemark.edges.forEach(({ node }) => {
        const slug = node.fields.slug
        const type = node.frontmatter.type
  
        createPage({
          path: slug,
          component: path.resolve('newsletter' === type ? `./src/templates/newsletter.js` : `./src/templates/episode.js`),
          context: { slug },
        })
      })
    })
  }
  