Gatsby 有没有办法修改《盖茨比》中的MDX frontmatter?
我正在使用Gatsby 有没有办法修改《盖茨比》中的MDX frontmatter?,gatsby,mdxjs,Gatsby,Mdxjs,我正在使用gatsby插件mdx和gatsby。我已经在frontmatter中添加了一个草稿字段,并且我希望在节点_ENV为生产“时将其值覆盖为始终为false。请注意,gatsby plugin draft似乎没有修改MDX AST,并且与gatsby plugin MDX不兼容。您可以在onCreateNode方法中执行此操作 您可以执行以下操作: // onCreateNode.js const { createFilePath } = require('gatsby-source-fi
gatsby插件mdx
和gatsby。我已经在frontmatter中添加了一个草稿
字段,并且我希望在节点_ENV
为生产“
时将其值覆盖为始终为false。请注意,gatsby plugin draft
似乎没有修改MDX AST,并且与gatsby plugin MDX
不兼容。您可以在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'],
})
}
}