text: const path = require('path');
  const _ = require('lodash');
  
  exports.createPages = ({ boundActionCreators, graphql }) => {
    const { createPage } = boundActionCreators;
  
    const blogPostTemplate = path.resolve('src/templates/post/index.js');
    const tagTemplate = path.resolve('src/templates/tags/index.js');
  
    return graphql(`
      {
        allMarkdownRemark(
          sort: { order: DESC, fields: [frontmatter___date] }
          limit: 1000
        ) {
          edges {
            node {
              frontmatter {
                path
                tags
                author
              }
            }
          }
        }
      }
    `).then(result => {
      if (result.errors) {
        return Promise.reject(result.errors);
      }
  
      const posts = result.data.allMarkdownRemark.edges;
      let tags = [];
  
      posts.forEach(({ node }) => {
        createPage({
          path: node.frontmatter.path,
          component: blogPostTemplate,
          context: {}, // additional data can be passed via context
        });
      });
  
      _.each(posts, edge => {
        if (_.get(edge, 'node.frontmatter.tags')) {
          tags = tags.concat(
            edge.node.frontmatter.tags,
            [edge.node.frontmatter.author]
          );
        }
      });
  
      // Eliminate duplicate tags
      tags = _.uniq(tags);
  
      // Make tag pages
      tags.forEach(tag => {
        createPage({
          path: `/tags/${_.kebabCase(tag)}/`,
          component: tagTemplate,
          context: {
            tag,
          },
        });
      });
    });
  };