Created
December 20, 2018 15:45
-
-
Save lonekorean/545cf25ea0c0a6e39d4d41441d75524f to your computer and use it in GitHub Desktop.
A chunk of my gatsby-node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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