homepage/gatsby-node.js

52 lines
1.0 KiB
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
2020-01-22 12:33:25 +00:00
edit
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
})
})
}
2020-01-22 12:33:25 +00:00
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type Mdx implements Node {
frontmatter: Frontmatter
}
type Frontmatter {
edit: String
}
`
createTypes(typeDefs)
}