Created
January 19, 2019 18:29
-
-
Save haxzie-xx/e0da6c695454dd8f22c2d938cf7e3b53 to your computer and use it in GitHub Desktop.
Interacting with Gatsby's node APIs to generate pages from Markdown files
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") | |
| exports.createPages = ({ actions, graphql }) => { | |
| const { createPage } = actions | |
| const blogPostTemplate = path.resolve(`src/templates/blog_template.js`) | |
| return graphql(` | |
| { | |
| allMarkdownRemark( | |
| limit: 100, | |
| sort: { order: DESC, fields: [frontmatter___date] } | |
| ) { | |
| edges { | |
| node { | |
| frontmatter { | |
| slug | |
| } | |
| } | |
| } | |
| } | |
| } | |
| `).then(result => { | |
| if (result.errors) { | |
| return Promise.reject(result.errors) | |
| } | |
| result.data.allMarkdownRemark.edges.forEach(({node}) => { | |
| createPage({ | |
| path: node.frontmatter.slug, | |
| component: blogPostTemplate, | |
| }) | |
| }) | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment