我正在和Gatsby一起使用gatsby-plugin-mdx。我已经在我的frontmatter中添加了一个draft字段,当NODE_ENV为"production"时,我想重写它的值,使其始终为false。请注意,gatsby-plugin-draft似乎不修改MDX AST,并且与gatsby-plugin-mdx不兼容。
发布于 2020-05-04 17:46:40
你可以在onCreateNode方法中做到这一点。
YOu可以执行以下操作:
// 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'],
})
}
}https://stackoverflow.com/questions/61582537
复制相似问题