Skip to content

Instantly share code, notes, and snippets.

@brookslyrette
Created January 1, 2019 18:02
Show Gist options
  • Save brookslyrette/482a32738c1e76bb056f1a29c17354b6 to your computer and use it in GitHub Desktop.
Save brookslyrette/482a32738c1e76bb056f1a29c17354b6 to your computer and use it in GitHub Desktop.
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