首页 > 解决方案 > 如何将帖子链接到作者

问题描述

我正在尝试为每个作者生成一个页面,包括他们的所有帖子 - 这是我的设置:

    {
      allAuthorsYaml {
        nodes {
          id
          title
        }
      }
    }
    {
      allFile(
        sort: { fields: childMarkdownRemark___frontmatter___date, order: DESC }
        filter: { sourceInstanceName: { eq: "posts" } }
      ) {
        edges {
          node {
            childMarkdownRemark {
              frontmatter {
                author {
                  title
                  id
                }
                date
                location
                title
                slug
                tags
              }
              html
            }
          }
        }
      }
    }
...
  mapping: {
    "MarkdownRemark.frontmatter.author": `AuthorsYaml`
  },
...

现在,我想做的是获取我所有作者的帖子列表,使用如下内容:

    {
      allAuthorsYaml {
        nodes {
          id
          title
          posts {
            frontmatter {
              date
              location
              title
              slug
              tags
            }
            html
          }
        }
      }
    }

实现这一目标的最有效方法是什么——遵循建议的 GraphQL 查询或一些替代的最佳实践?

谢谢!

标签: graphqlyamlgatsbyrelation

解决方案


推荐阅读