Skip to content

Instantly share code, notes, and snippets.

@lonekorean
Created Dec 20, 2018
Embed
What would you like to do?
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