Created
May 12, 2018 00:18
-
-
Save camsloanftc/0e6095cb9d08a08804a4d5b7a3692730 to your computer and use it in GitHub Desktop.
Example of a gatsby-node file
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
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