我必须将存档小部件添加到基于 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 操作?