mirror of
https://github.com/kingomarnajjar/gatsby-starter-netlify-cms.git
synced 2026-07-25 22:27:24 +10:00
Closes #47 See for background5bc432b71d (commitcomment-27821888)5bc432b71d (commitcomment-27821874)+ links in #47 thanks @KyleAMathews
41 lines
949 B
JavaScript
41 lines
949 B
JavaScript
const path = require('path')
|
|
|
|
exports.createPages = ({ boundActionCreators, graphql }) => {
|
|
const { createPage } = boundActionCreators
|
|
|
|
return graphql(`
|
|
{
|
|
allMarkdownRemark(limit: 1000) {
|
|
edges {
|
|
node {
|
|
id
|
|
frontmatter {
|
|
path
|
|
templateKey
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`).then(result => {
|
|
if (result.errors) {
|
|
result.errors.forEach(e => console.error(e.toString()))
|
|
return Promise.reject(result.errors)
|
|
}
|
|
|
|
result.data.allMarkdownRemark.edges.forEach(edge => {
|
|
const id = edge.node.id
|
|
const pagePath = edge.node.frontmatter.path
|
|
createPage({
|
|
path: pagePath,
|
|
component: path.resolve(
|
|
`src/templates/${String(edge.node.frontmatter.templateKey)}.js`
|
|
),
|
|
// additional data can be passed via context
|
|
context: {
|
|
id,
|
|
},
|
|
})
|
|
})
|
|
})
|
|
}
|