reactjs - Gatsby - gatsby-plugin-categories 的 Graphql 错误“未由 MarkdownRemarkFieldsFilterInput 类型定义”
问题描述
预期结果
我应该能够看到一个类别页面。我完全按照文档在https://www.npmjs.com/package/gatsby-plugin-categories上所说的做了
实际结果
收到构建错误
error GraphQL Error Field "category" is not defined by type MarkdownRemarkFieldsFilterInput.
代码
src/模板/category.js
import React from "react";
import Helmet from "react-helmet";
import { graphql } from "gatsby";
import Layout from "../layout";
import PostListing from "../components/PostListing";
export default class CategoryTemplate extends React.Component {
render() {
const { pageContext, data } = this.props;
const { category } = pageContext;
return (
<Layout>
<div className="category-container">
<Helmet title={`Posts in category "${category}"`} />
<PostListing postEdges={data.allMarkdownRemark.edges} />
</div>
</Layout>
);
}
}
export const pageQuery = graphql`
query CategoryPage($category: String) {
allMarkdownRemark(
limit: 1000
filter: { fields: { category: { eq: $category } } }
) {
totalCount
edges {
node {
fields {
slug
category
}
excerpt
timeToRead
frontmatter {
title
tags
date
}
}
}
}
}
`;
盖茨比-config.js
module.exports = {
siteMetadata: {
title: `VLLG`,
description: `Village | California Campsites.`,
author: `Juan Gallardo`,
},
plugins: [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `pages`,
path: `${__dirname}/src/pages/`,
},
},
{
resolve: `gatsby-transformer-remark`,
options: {
// CommonMark mode (default: true)
commonmark: true,
// Footnotes mode (default: true)
footnotes: true,
// Pedantic mode (default: true)
pedantic: true,
// GitHub Flavored Markdown mode (default: true)
gfm: true,
// Plugins configs
plugins: [],
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `VLLG`,
short_name: `vllg`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// 'gatsby-plugin-offline',
],
}
我如何将类别添加到帖子中(在 .md 文件中)
category: 'lol'
博客文章的结构
Graphql 查询的结果
解决方案
推荐阅读
- matlab - 如何根据任一向量的条件修改多个向量?
- javascript - 如何处理@jupyterlab/apputils 对话框点击事件 | Jupyterlab 扩展
- azure - 如何向 Azure 上的 VM 添加多个网卡?
- cypress - 通过打开和运行命令运行多个赛普拉斯规范时的不同行为
- sql - 如何检查是否为空,如果参数为空,则使用 IS NULL 检查值
- sql - 带有单选或多选且没有正确/错误答案的问卷的模式设计
- git - Git 历史包含许多以前接受的 PR 的提交
- oracle - Oracle plsql 触发器
- javascript - 是否使用“npm install -g my-package”安装了 devDependencies?
- docker - 使用上次启动时已经包含文件的卷在 docker 上运行 confluence