homepage/gatsby-node.js

40 lines
821 B
JavaScript
Raw Normal View History

2019-12-12 21:27:56 +00:00
const path = require(`path`)
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions
2019-12-13 14:51:59 +00:00
const siteTemplate = path.resolve(`src/templates/siteTemplate.js`)
2019-12-12 21:27:56 +00:00
const result = await graphql(`
{
2019-12-14 17:03:07 +00:00
allMdx(limit: 1000) {
2019-12-12 21:27:56 +00:00
edges {
node {
frontmatter {
path
title
2019-12-14 17:03:07 +00:00
edit {
relativePath
}
2019-12-12 21:27:56 +00:00
}
}
}
}
}
`)
// Handle errors
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`)
return
}
2019-12-12 23:03:04 +00:00
result.data.allMdx.edges.forEach(({ node }) => {
2019-12-12 21:27:56 +00:00
createPage({
path: node.frontmatter.path,
2019-12-13 14:51:59 +00:00
component: siteTemplate,
2019-12-12 21:27:56 +00:00
context: {}, // additional data can be passed via context
})
})
}