-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from newrelic/liz/add-markdown-pages
Add markdown page generation
- Loading branch information
Showing
6 changed files
with
978 additions
and
85 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
/** | ||
* Implement Gatsby's Node APIs in this file. | ||
* | ||
* See: https://www.gatsbyjs.org/docs/node-apis/ | ||
*/ | ||
const path = require(`path`); | ||
|
||
// You can delete this file if you're not using it | ||
exports.createPages = async ({ actions, graphql, reporter }) => { | ||
const { createPage } = actions; | ||
|
||
const result = await graphql(` | ||
{ | ||
allMarkdownRemark( | ||
sort: { order: DESC, fields: [frontmatter___date] } | ||
limit: 1000 | ||
) { | ||
edges { | ||
node { | ||
frontmatter { | ||
path | ||
template | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
// Handle errors | ||
if (result.errors) { | ||
reporter.panicOnBuild(`Error while running GraphQL query.`); | ||
return; | ||
} | ||
|
||
result.data.allMarkdownRemark.edges.forEach(({ node }) => { | ||
createPage({ | ||
path: node.frontmatter.path, | ||
component: path.resolve(`src/templates/${node.frontmatter.template}.js`), | ||
context: {}, // additional data can be passed via context | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.