【问题标题】:Gatsby v4 - Joining Author Details Into a Post [closed]Gatsby v4 - 将作者详细信息加入帖子[关闭]
【发布时间】: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.authornull

在 gatsby-config.js 我有:

        {
            resolve: `gatsby-source-filesystem`,
            options: {
                path: `${__dirname}/content/authors`,
                name: `authors`
            }
        },

    mapping: {
        'MarkdownRemark.frontmatter.author': `AuthorYaml`
    }

但这无济于事。与 Gatsby v2 相同的代码在转换到 v4 时停止工作。

【问题讨论】:

  • 你用的是切片机吗?
  • 不,但事实证明是其他地方的错字导致了这种情况。

标签: graphql gatsby


【解决方案1】:

原来是在不同的地方有一个错字导致了这种情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-24
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    • 2011-11-19
    • 2011-04-21
    • 1970-01-01
    • 2022-01-20
    相关资源
    最近更新 更多