问题描述
我想创建标签云(或类别列表),该标签云应链接到相应的标签文章和类别。但是在我构建的查询中,仅将name
或slug
连接在一起,因为它们放置在fields
或frontmatter
中,而不是放置在一个对象中
我使用这两个广泛使用的插件: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 }
});