如何使用NetlifyCMS和Gatsby将子弹显示在graphql中?

And*_* II 3 gatsby netlify netlify-cms

在站点上添加netlify cms时,如何将子弹显示在graphql中?我有一个博客文章集,除了子弹外,所有内容都显示出来:

backend:
  name: git-gateway
  branch: master # Branch to update (optional; defaults to master)

media_folder: static/images
public_folder: /images

collections:
  - name: "blog"
  label: "Blog"
  folder: "content/blogPost"
  create: true
  slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
  fields: # The fields for each document, usually in front matter
    - { label: "Layout", name: "layout", widget: "hidden", default: "blog" }
    - { label: "Title", name: "title", widget: "string" }
    - { label: "Publish Date", name: "date", widget: "datetime" }
    - { label: "Featured Image", name: "thumbnail", widget: "image" }
    - { label: "Body", name: "body", widget: "markdown" }
Run Code Online (Sandbox Code Playgroud)

这是我的graphql查询: 在此处输入图片说明

tal*_*ves 6

slug在GraphQL查询是不是在该领域的frontmatter的一部分config.yml。这些段字段无关。您在查询中指的是Gatsby中的节点。

fields您的中缺少上述GraphQL查询中的值node。如下例所示,必须通过gatsby-node.js添加配置来使用它:

const { createFilePath } = require('gatsby-source-filesystem')

exports.onCreateNode = ({ node, boundActionCreators, getNode }) => {
  const { createNodeField } = boundActionCreators

  if (node.internal.type === `MarkdownRemark`) {
    const value = createFilePath({ node, getNode })
    createNodeField({
      name: `slug`,
      node,
      value,
    })
  }
}
Run Code Online (Sandbox Code Playgroud)