text: const path = require(`path`);
  const { createFilePath } = require(`gatsby-source-filesystem`);
  // import _ from 'lodash';
  
  exports.createPages = ({ graphql, actions }) => {
    const { createPage, createRedirect } = actions;
  
    createRedirect({
      fromPath: `/posts/2019-04-15-dokku-create-your-own-paas/`,
      isPermanent: true,
      redirectInBrowser: true,
      toPath: `/posts/dokku-create-your-own-paas/`,
    });
  
    const blogPost = path.resolve(`./src/templates/blog-post.js`);
    return graphql(
      `
        {
          allMarkdownRemark(
            filter: { frontmatter: { published: { eq: true } } }
            sort: { fields: [frontmatter___date], order: DESC }
            limit: 1000
          ) {
            edges {
              node {
                fields {
                  slug
                }
                frontmatter {
                  title
                }
              }
            }
          }
        }
      `
    ).then((result) => {
      if (result.errors) {
        throw result.errors;
      }
  
      // Create blog posts pages.
      const posts = result.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({
          path: post.node.fields.slug,
          component: blogPost,
          context: {
            slug: post.node.fields.slug,
            previous,
            next,
          },
        });
      });
  
      // Tag pages:
      // let tags = [];
      // // Iterate through each post, putting all found tags into `tags`
      // _.each(posts, edge => {
      //   if (_.get(edge, "node.frontmatter.tags")) {
      //     tags = tags.concat(edge.node.frontmatter.tags);
      //   }
      // });
      // // Eliminate duplicate tags
      // tags = _.uniq(tags);
  
      // // Make tag pages
      // tags.forEach(tag => {
      //   createPage({
      //     path: `/tags/${_.kebabCase(tag)}/`,
      //     component: tagTemplate,
      //     context: {
      //       tag
      //     }
      //   });
      // });
    });
  };
  
  exports.onCreateNode = ({ node, actions, getNode }) => {
    const { createNodeField } = actions;
  
    if (node.internal.type === `MarkdownRemark`) {
      const value = createFilePath({ node, getNode });
      createNodeField({
        name: `slug`,
        node,
        value,
      });
    }
  };
  