Skip to content

Instantly share code, notes, and snippets.

@DSchau
Created January 29, 2019 17:02
Show Gist options
  • Select an option

  • Save DSchau/ffa01c29214cba0cb8576d637b92bd97 to your computer and use it in GitHub Desktop.

Select an option

Save DSchau/ffa01c29214cba0cb8576d637b92bd97 to your computer and use it in GitHub Desktop.
Example with Gatsby Node APIs
const path = require('path')
const { createPages } = require('gatsby/node')
createPages(async ({ actions, graphql }) => {
const { createPage } = actions
const result = await graphql(`
{
allMarkdownRemark {
edges {
node {
fields {
slug
}
}
}
}
}
`)
.then(res => {
if (res.errors) {
throw res.errors
}
return res.data
})
const templates = {
blogPost: path.resolve('src/templates/blog-post.js')
}
result.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
component: templates.blogPost,
path: node.fields.slug,
context: {
slug
}
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment