mirror of
https://github.com/nodejs/node.git
synced 2025-05-14 21:30:13 +00:00

PR-URL: https://github.com/nodejs/node/pull/30271 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
44 lines
974 B
JavaScript
44 lines
974 B
JavaScript
const {createFilePath} = require('gatsby-source-filesystem')
|
|
const path = require('path')
|
|
|
|
exports.onCreateNode = ({node, getNode, actions}) => {
|
|
const {createNodeField} = actions
|
|
if (node.internal.type === 'MarkdownRemark') {
|
|
const slug = createFilePath({node, getNode, basePath: 'content', trailingSlash: false})
|
|
createNodeField({
|
|
node,
|
|
name: 'slug',
|
|
value: slug
|
|
})
|
|
}
|
|
}
|
|
|
|
exports.createPages = ({graphql, actions}) => {
|
|
const {createPage} = actions
|
|
return graphql(`
|
|
{
|
|
allMarkdownRemark {
|
|
edges {
|
|
node {
|
|
id
|
|
fields {
|
|
slug
|
|
}
|
|
html
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`).then(result => {
|
|
result.data.allMarkdownRemark.edges.forEach(({node}) => {
|
|
createPage({
|
|
path: node.fields.slug,
|
|
component: path.resolve('./src/templates/Page.js'),
|
|
context: {
|
|
slug: node.fields.slug
|
|
}
|
|
})
|
|
})
|
|
})
|
|
}
|