微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用gatsby-plugin-categories / gatsby-plugin-tags标记云和类别列表

如何解决使用gatsby-plugin-categories / gatsby-plugin-tags标记云和类别列表

我想创建标签云(或类别列表),该标签云链接到相应的标签文章和类别。但是在我构建的查询中,仅将nameslug连接在一起,因为它们放置在fieldsfrontmatter中,而不是放置在一个对象中

我使用这两个广泛使用的插件https://github.com/rmcfadzean/gatsby-pantry

这是我当前的查询

{
  tags: allMarkdownRemark(filter: {frontmatter: {title: {ne: ""}}}) {
    group(field: frontmatter___tags) {
      fieldValue
      totalCount
      edges {
        node {
          fields {
            tags
          }
          frontmatter {
            tags
          }
        }
      }
    }
  }
}

{
  "data": {
    "allMarkdownRemark": {
      "group": [
        {
          "fieldValue": "Another tag","totalCount": 1,"edges": [
            {
              "node": {
                "fields": {
                  "tags": [
                    "another-tag","my-example","post"
                  ]
                },"frontmatter": {
                  "tags": [
                    "Another tag","My example","Post"
                  ]
                }
              }
            }
          ]
        },{
          "fieldValue": "Example","edges": [
            {
              "node": {
                "fields": {
                  "tags": [
                    "example","frontmatter": {
                  "tags": [
                    "Example",{
          "fieldValue": "My example",{
          "fieldValue": "Post","totalCount": 2,"Post"
                  ]
                }
              }
            },{
              "node": {
                "fields": {
                  "tags": [
                    "example","Post"
                  ]
                }
              }
            }
          ]
        }
      ]
    }
  },}

如何获取类似这样的对象:

{ "tags": 
  [
   { "slug": "another-tag","frontmatter": "Another Tag"},{ "slug": "example","frontmatter": "Example"}
  ]
}

解决方法

我当前的方法是在视图本身中。我遍历fields.tags并在数组中搜索它们。我保存了索引并将其用于frontmatter.tags(它们的顺序很愉快)

正是该代码:

    DiscoveryDocumentResponse disco = 
    await client.GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest { 
                    Address = "http://<identity-url>",Policy = { RequireHttps = false } 
                });

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。