Skip to content

Instantly share code, notes, and snippets.

@camsloanftc
Created May 12, 2018 00:18
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 camsloanftc/0e6095cb9d08a08804a4d5b7a3692730 to your computer and use it in GitHub Desktop.
Save camsloanftc/0e6095cb9d08a08804a4d5b7a3692730 to your computer and use it in GitHub Desktop.
Example of a gatsby-node file
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators
return new Promise((resolve, reject) => {
graphql(
`
{
allContentfulBlogPost {
edges {
node {
id
title
slug
category {
id
title
}
}
}
}
}
`
)
.then(result => {
if (result.errors) {
reject(result.errors)
}
const postTemplate = path.resolve('./src/templates/SinglePost/SinglePost.js')
each(result.data.allContentfulBlogPost.edges, edge => {
const slug = `/blog/${edge.node.slug}/`
createPage({
path: slug,
component: slash(postTemplate),
layout: `blog-layout`,
context: {
id: edge.node.id,
slug,
category: edge.node.category.id,
},
})
})
resolve()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment