我正在gatsby-plugin-mdx与盖茨比一起使用。我在draft我的 frontmatter 中添加了一个字段,我想在 is 时将其值覆盖为始终为NODE_ENVfalse "production"。请注意,这gatsby-plugin-draft似乎不会修改 MDX AST 并且与gatsby-plugin-mdx.
1 回答
2
你可以在onCreateNode方法中做到这一点。
您可以执行以下操作:
// onCreateNode.js
const { createFilePath } = require('gatsby-source-filesystem')
module.exports = ({ node, getNode, actions }) => {
const { createNodeField } = actions
if (node.internal.type === 'Mdx') {
const slug = createFilePath({ node, getNode, basePath: 'pages' })
const isProduction = ... // TODO: implement
createNodeField({
node,
name: 'draft',
value: isProduction? false : node.frontmatter['draft'],
})
}
}
于 2020-05-04T09:46:40.443 回答