Skip to content

Instantly share code, notes, and snippets.

@amandeepmittal
Created November 17, 2018 09:12
Show Gist options
  • Save amandeepmittal/ebc80bce480ec1b37ec5bcd9ff24058d to your computer and use it in GitHub Desktop.
Save amandeepmittal/ebc80bce480ec1b37ec5bcd9ff24058d to your computer and use it in GitHub Desktop.
const path = require('path');
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
return new Promise((resolve, reject) => {
const blogPostTemplate = path.resolve('src/templates/blogPost.js');
// Query for markdown nodes to use in creating pages.
resolve(
graphql(
`
query {
allMarkdownRemark(
sort: { order: ASC, fields: [frontmatter___date] }
) {
edges {
node {
frontmatter {
path
title
tags
}
}
}
}
}
`
).then(result => {
const posts = result.data.allMarkdownRemark.edges;
posts.forEach(({ node }) => {
const path = node.frontmatter.path;
createPage({
path,
component: blogPostTemplate,
context: {
pathSlug: path
}
});
resolve();
});
})
);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment