【发布时间】:2022-04-20 02:45:14
【问题描述】:
使用 Gatsby v4。在我的博文中有一个字段author。有一个单独的作者文件,其中包含博客文章作者的详细信息 - 全名和头像。
发布文件:
---
date: "2021-12-31"
title: "Happy New Year"
author: chuck
---
## Happy New Year!
content/authors/author.yaml
- id: chuck
name: Chuck Norris
avatar: chuck.jpg
GraphQL 如下所示:
export const pageQuery = graphql`
query($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
html
excerpt(pruneLength: 200)
frontmatter {
title
author {
id
name
avatar
},
}
fields {
slug
readingTime {
minutes
}
}
}
}
但在 BlogPost 模板中,data.markdownRemark.frontmatter.author 是 null。
在 gatsby-config.js 我有:
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/content/authors`,
name: `authors`
}
},
和
mapping: {
'MarkdownRemark.frontmatter.author': `AuthorYaml`
}
但这无济于事。与 Gatsby v2 相同的代码在转换到 v4 时停止工作。
【问题讨论】:
-
你用的是切片机吗?
-
不,但事实证明是其他地方的错字导致了这种情况。