MarkdownRemarkFrontmatterFilterInput.类型未定义字段“类别”,这意味着什么,请告知。
我使用Netlify CMS作为内容管理器与Gatsbyjs前端。我使用这个初学者模板https://github.com/netlify-templates/gatsby-starter-netlify-cms,就像他们显示标记一样,所以我复制了它的标记相关文件,并将标记替换为类别集合,并在config.yml文件中添加了类别集合。下面是密码。生成错误 https://prnt.sc/sb6pwd错误在index.js文件中。
category.js,这是我的模板文件,用于列出所有类别和该类别的博客总数
import React from 'react'
import { Helmet } from 'react-helmet'
import { Link, graphql } from 'gatsby'
import Layout from '../components/Layout'
class CategoryRoute extends React.Component {
render() {
const posts = this.props.data.allMarkdownRemark.edges
const postLinks = posts.map((post) => (
<li key={post.node.fields.slug}>
<Link to={post.node.fields.slug}>
<h2 className="is-size-2">{post.node.frontmatter.title}</h2>
</Link>
</li>
))
const category = this.props.pageContext.category
const title = this.props.data.site.siteMetadata.title
const totalCount = this.props.data.allMarkdownRemark.totalCount
const categoryHeader = `${totalCount} post${
totalCount === 1 ? '' : 's'
} tagged with “${category}”`
return (
<Layout>
<section className="section">
<Helmet title={`${category} | ${title}`} />
<div className="container content">
<div className="columns">
<div
className="column is-10 is-offset-1"
style={{ marginBottom: '6rem' }}
>
<h3 className="title is-size-4 is-bold-light">{categoryHeader}</h3>
<ul className="taglist">{postLinks}</ul>
<p>
<Link to="/category/">Browse all category</Link>
</p>
</div>
</div>
</div>
</section>
</Layout>
)
}
}
export default CategoryRoute
export const categoryPageQuery = graphql`
query CategoryPage($category: String) {
site {
siteMetadata {
title
}
}
allMarkdownRemark(
limit: 1000
sort: { fields: [frontmatter___date], order: DESC }
filter: { frontmatter: { category: { in: [$category] } } }
) {
totalCount
edges {
node {
fields {
slug
}
frontmatter {
title
}
}
}
}
}
`index.js
import React from 'react'
import { kebabCase } from 'lodash'
import { Helmet } from 'react-helmet'
import { Link, graphql } from 'gatsby'
import Layout from '../../components/Layout'
const CategoryPage = ({
data: {
allMarkdownRemark: { group },
site: {
siteMetadata: { title },
},
},
}) => (
<Layout>
<section className="section">
<Helmet title={`Category | ${title}`} />
<div className="container content">
<div className="columns">
<div
className="column is-10 is-offset-1"
style={{ marginBottom: '6rem' }}
>
<h1 className="title is-size-2 is-bold-light">Categories</h1>
<ul className="taglist">
{group.map((category) => (
<li key={category.fieldValue}>
<Link to={`/category/${kebabCase(category.fieldValue)}/`}>
{category.fieldValue} ({category.totalCount})
</Link>
</li>
))}
</ul>
</div>
</div>
</div>
</section>
</Layout>
)
export default CategoryPage
export const categoryPageQuery = graphql`
query CategoryQuery {
site {
siteMetadata {
title
}
}
allMarkdownRemark(limit: 1000) {
group(field: frontmatter___category) {
fieldValue
totalCount
}
}
}
`Config.yml类别集合声明:
- name: category
label: Category
identifier_field: slug
folder: src/pages/blog/category
create: true
fields:
-label: Template Key
name: templateKey
widget: hidden
default: category
- label: Category
name: category
widget: string
- label: Category Image
name: category_img
widget: image
- label: Slug
name: slug
widget: string
- name: blog
label: Blog
folder: src/pages/blog
create: true
slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
fields:
- label: Template Key
name: templateKey
widget: hidden
default: blog-post
- label: Title
name: title
widget: string
- label: Path
name: path
widget: hidden
default: blog-post
- label: Publish Date
name: date
widget: datetime
- label: Description
name: description
widget: text
- label: Featured Post
name: featuredpost
widget: boolean
- label: Featured Image
name: featuredimage
widget: image
- label: Body
name: body
widget: markdown
- label: Tags
name: tags
widget: list
- label: Category
name: category
widget: select
options:
- label: Iraq
value: iraq
- label: Personal
value: personal
- label: Productivity
value: productivity
- label: Software Development
value: software-development
- label: Uncategorized
value: uncategorized发布于 2020-10-04 19:27:02
您需要为该字段添加一些初始数据。如果您查看控制台,可能会看到如下所示:
添加至少一个条目
https://stackoverflow.com/questions/61610133
复制相似问题