Skip to content

Instantly share code, notes, and snippets.

@lonekorean
Created December 20, 2018 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lonekorean/545cf25ea0c0a6e39d4d41441d75524f to your computer and use it in GitHub Desktop.
Save lonekorean/545cf25ea0c0a6e39d4d41441d75524f to your computer and use it in GitHub Desktop.
A chunk of my gatsby-node.js
exports.createPages = ({ graphql, actions }) => {
return new Promise((resolve, reject) => {
graphql(`
{
allMarkdownRemark(
sort: { fields: [frontmatter___date], order: DESC }
) {
edges {
node {
fields {
slug
}
}
}
}
}
`).then(result => {
if (result.errors) {
reject(result.errors);
} else {
const posts = result.data.allMarkdownRemark.edges;
// create blog post pages
posts.forEach(({ node }) => {
actions.createPage({
path: '/blog/' + node.fields.slug + '/',
component: path.resolve('./src/templates/whatever-your-heart-desires.js'),
context: {
slug: node.fields.slug
}
});
});
// more code blah blah blah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment