wordpress - Gridsome + Wordpress 源插件 - 如何按月和年添加存档路线
问题描述
我必须将存档小部件添加到基于 Gridsome(Wordpress 作为数据源)的博客中。像这样的标准功能:
我用静态查询获取帖子:
query Home($page: Int) {
allWordPressPost(page: $page) {
pageInfo {
totalPages
currentPage
}
edges {
node {
date(format: "YYYY-MM-DD")
id
title
path
}
}
}
}
接下来在按月挂钩上,我按年和月将数据分组到这样的输出:
{
"2019": {
"10": [
{
"date": "2019-10-29",
"node": {
"date": "2019-10-29",
"id": "145",
"title": "Aspernatur ipsam est omnis praesentium rerum autem",
"path": "/2019/10/29/aspernatur-ipsam-est-omnis-praesentium-rerum-autem/"
}
},
{
"date": "2019-10-29",
"node": {
"date": "2019-10-29",
"id": "121",
"title": "Libero voluptatibus facere aspernatur",
"path": "/2019/10/29/libero-voluptatibus-facere-aspernatur/"
}
}
],
"09": [
{
"date": "2019-09-25",
"node": {
"date": "2019-09-25",
"id": "1",
"title": "Hello world!",
"path": "/2019/09/25/hello-world/"
}
}
]
}
}
我使用标准 v-for 循环语法生成了小部件链接结构,但是示例路由,例如:“ http://localhost:8080/blog/2018 ”、“ http://localhost:8080/blog/2018/19 ”到404页面。我尝试通过添加以下内容来修改 gridsome.config.js:
templates: {
WordPressArchive: [
{
path: "/blog/:year",
component: "./src/templates/WordPressArchive.vue"
}
]
},
它导致错误:
"Error: A content type for the WordPressArchive template does not exist"
如何在 Gridsome 中启用存档路由以按年和年/月过滤博客文章?
"/blog/:year",
"/blog/:year/:month"
是否有可能直接从 graphQL 查询中按日期和年份对帖子进行分组,而无需进一步的 js 操作?
解决方案
您的 GraphQL 中有一个WordPressPost
类型,并且您正尝试将其WordPressArchive
用作模板名称。这些需要匹配,要么typeName
在 GraphQL 中更改,要么在gridsome.config.js
.
推荐阅读
- python-3.x - 使用 panda python 使用多个 csv 文件时,绘图图未更正
- python - 如何为 sum() 准备价格清单
- java - 如何在 Java SSL 中启用特定的签名算法
- java - 谷歌地图 MapsView 泄露
- php - 如何在 Symfony 3.4 (PHP) 中注册 Google OAuth 包
- reporting-services - 在 SSRS Tablix 中呈现 HTML 标签
- javascript - 我们如何禁用输入类型 =“日期”中的 dd-mm-yyyy 字段,以便只接受选定的日期
- karate - 使用 karate.forEach 和 karate.set 从 json 数组中提取值的索引
- javascript - Firebase 网络将聊天存储为实时数据库中的数组
- java - 为什么eclipse不在方法参数中使用菱形运算符