homepage/gatsby-node.js

65 lines
1.3 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(`
{
2020-02-18 23:00:11 +00:00
allMdx(limit: 1000, filter: { fields: { source: { eq: "pages" } } }) {
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
2020-02-18 23:00:11 +00:00
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions
if (node.internal.type === `Mdx`) {
const value = getNode(node.parent).sourceInstanceName
createNodeField({
node,
name: `source`,
value,
})
}
}
2020-01-22 12:33:25 +00:00
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type Mdx implements Node {
2020-02-18 23:00:11 +00:00
frontmatter: Frontmatter
2020-01-22 12:33:25 +00:00
}
type Frontmatter {
edit: String
}
`
createTypes(typeDefs)
}