首页 > 解决方案 > 盖茨比无法查询frontmatter

问题描述

我现在正在学习 Gatsby.js,但遇到了问题。我已经安装了转换器插件,并且我有一个 .md 文件,其中有标题、堆栈和 slug。

title :Place Sharing Website
stack :React.js & Node.js
slug :place-sharing
---

### You can share the places that you visited

我想查询那个标题、堆栈和 slug。但我不能那样做。这是我试图这样做的代码。

allMarkdownRemark {
  nodes {
    frontmatter {
      title
      stack
      slug
    }
  }
}
}

它没有用。

这是我的 gatsby.config 文件

module.exports = {
  plugins: [
    "gatsby-transformer-remark",
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `notes`,
        path: `${__dirname}/src/notes/`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `projects`,
        path: `${__dirname}/src/projects/`,
      },
    },
  ],
  siteMetadata: {
    title: "My Homepage",
    description: "This is where I write my thoughts.",
  },
}

这是我试图查询它的方式。

知道我做错了什么吗?

标签: markdowngatsby

解决方案


我认为你有格式问题。尝试:

title: Place Sharing Website
stack: React.js & Node.js
slug: place-sharing

并检查 markdown 文件的创建,字段应包含在---.


推荐阅读