我试图像这样在onCreateNode()上获取MarkdownRemark节点。
exports.onCreateNode = ({ getNodesByType, node }) => {
if (node.internal.type === 'Directory') {
const markdowns = getNodesByType('MarkdownRemark');
console.log(markdowns); // empty array
}
};
我想当我访问markdown文件时,还没有创建markdown节点,因为首先创建了目录节点。
有什么方法可以访问降价节点?谢谢您的提前答复!
那是我的gatsby-config.js:)
module.exports = {
siteMetadata: { title:'site' },
plugins: [
{
resolve: 'gatsby-plugin-manifest',
options: {
name: 'gatsby-starter-default',
short_name: 'starter',
start_url: '/',
background_color: '#663399',
theme_color: '#663399',
display: 'minimal-ui',
icon: 'src/images/gatsby-icon.png'
},
},
'gatsby-plugin-react-helmet',
'gatsby-plugin-typescript',
{
resolve: 'gatsby-plugin-linaria',
options: {
preprocessor: 'none',
sourceMap: process.env.NODE_ENV === 'production' ? false : true
},
},
'gatsby-plugin-sass',
'gatsby-plugin-sharp',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'images',
path: `${__dirname}/src/images`,
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'posts',
path: `${__dirname}/src/posts`,
},
},
'gatsby-transformer-remark',
'gatsby-transformer-sharp'
]
}