Gridsome + Wordpress source plugin - How to add archive routes by month and year

只愿长相守 提交于 2020-01-16 08:43:45

问题


I have to add an archive widget to a blog based on Gridsome (Wordpress as data source). Standard feature like this one:

I fetched posts with static query:

query Home($page: Int) {
  allWordPressPost(page: $page) {
    pageInfo {
      totalPages
      currentPage
    }
    edges {
      node {
        date(format: "YYYY-MM-DD")
        id
        title
        path

      }
    }
  }
}

Next on monthed hook, i grouped data by year and month to such output:

 {
  "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/"
        }
      }
    ]
  }
}

I generated widget links structure using and standard v-for loop syntax, but sample routes such as: "http://localhost:8080/blog/2018", "http://localhost:8080/blog/2018/19" go to the 404 page. I tried to modify gridsome.config.js by adding:

  templates: {
    WordPressArchive: [
      {
        path: "/blog/:year",
        component: "./src/templates/WordPressArchive.vue"
      }
    ]

  },

It results in error:

 "Error: A content type for the WordPressArchive template does not exist"

How can i enable archive routes in Gridsome to filter blog posts by year and year/month ?

"/blog/:year",
"/blog/:year/:month"

Is there a possibility to group posts by date and year directly from graphQL query, without further js manipulations?

来源:https://stackoverflow.com/questions/58635769/gridsome-wordpress-source-plugin-how-to-add-archive-routes-by-month-and-year

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!