Created
January 29, 2019 17:02
-
-
Save DSchau/ffa01c29214cba0cb8576d637b92bd97 to your computer and use it in GitHub Desktop.
Example with Gatsby Node APIs
This file contains hidden or 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') | |
| 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