2020-07-17 14:59:20 +02:00
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
async function createMarkdownPages(graphql, actions) {
|
|
|
|
const { createPage } = actions
|
|
|
|
|
|
|
|
const markdownPageTemplate = path.resolve(
|
2021-10-13 18:48:59 +02:00
|
|
|
'./src/components/@shared/Page/PageMarkdown.tsx'
|
2020-07-17 14:59:20 +02:00
|
|
|
)
|
|
|
|
// Grab all markdown files with a frontmatter title defined
|
|
|
|
const markdownResult = await graphql(`
|
|
|
|
{
|
|
|
|
allMarkdownRemark(filter: { frontmatter: { title: { ne: "" } } }) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
fields {
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
|
|
|
|
if (markdownResult.errors) {
|
|
|
|
throw markdownResult.errors
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create markdown pages.
|
|
|
|
const markdownPages = markdownResult.data.allMarkdownRemark.edges
|
|
|
|
|
|
|
|
markdownPages.forEach((page) => {
|
|
|
|
createPage({
|
|
|
|
path: page.node.fields.slug,
|
|
|
|
component: markdownPageTemplate,
|
|
|
|
context: {
|
|
|
|
slug: page.node.fields.slug
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = createMarkdownPages
|