在站点上添加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" }
答案 0 :(得分:2)
GraphQL查询中的slug
并不是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,
})
}
}