Created
January 1, 2019 18:02
-
-
Save brookslyrette/482a32738c1e76bb056f1a29c17354b6 to your computer and use it in GitHub Desktop.
This file contains 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
const path = require(`path`) | |
exports.createPages = ({ graphql, actions }) => { | |
const { createPage } = actions | |
return new Promise((resolve) => { | |
graphql(` | |
{ | |
allPostsJson(sort: { fields: published_at, order: DESC }, filter: { status: { eq: "published" } }) { | |
edges { | |
node { | |
id, slug, title, published_at, status, markdown, html | |
} | |
} | |
} | |
} | |
`).then(result => { | |
result.data.allPostsJson.edges.forEach(({ node }) => { | |
createPage( | |
{ | |
path: node.slug, | |
component: path.resolve(`./src/templates/post.js`), | |
context: { | |
// Data passed to context is available | |
// in page queries as GraphQL variables. | |
post: node, | |
}, | |
}) | |
}) | |
resolve() | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment