From fbd2da391ab71eb036f0bee7aff3cb27f3893c18 Mon Sep 17 00:00:00 2001 From: hamdy Date: Mon, 30 Nov 2020 14:02:35 +0200 Subject: [PATCH] fix tags --- gridsome.config.js | 2 +- gridsome.server.js | 34 +++++++++++++++++++++ src/templates/Tag.vue | 69 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 95 insertions(+), 10 deletions(-) diff --git a/gridsome.config.js b/gridsome.config.js index e657df240..5c8e3f8d5 100644 --- a/gridsome.config.js +++ b/gridsome.config.js @@ -176,7 +176,7 @@ module.exports = { }], ProjectTag: [{ - path: '/tags/:id', + path: '/projects/tags/:id', component: '~/templates/Tag.vue' }], diff --git a/gridsome.server.js b/gridsome.server.js index 9bc8ae3dd..45bbc2f0a 100644 --- a/gridsome.server.js +++ b/gridsome.server.js @@ -212,4 +212,38 @@ module.exports = function(api) { }); }); + +api.createPages(async({ + graphql, + createPage +}) => { + // Use the Pages API here: https://gridsome.org/docs/pages-api + const { + data + } = await graphql(`{ + allNewsTag { + edges { + + node { + id + path + } + } + } +} +`); + + data.allNewsTag.edges.forEach(function(element) { + createPage({ + path: element.node.path, + component: './src/templates/Tag.vue', + context: { + id: element.node.id + } + }); + + }); + +}); + } \ No newline at end of file diff --git a/src/templates/Tag.vue b/src/templates/Tag.vue index a5f223dce..b1d7eedbb 100644 --- a/src/templates/Tag.vue +++ b/src/templates/Tag.vue @@ -2,12 +2,11 @@
-

{{ $page.projectTag.title }}

+

{{ tags.title }}

- A {{ $page.projectTag.belongsTo.totalCount }} Projects + >{{ tags.belongsTo.totalCount }} {{item}}

@@ -15,7 +14,7 @@
@@ -23,11 +22,11 @@
@@ -70,11 +69,52 @@ humanTime : startdate(format:"DD MMM YYYY") datetime : created + } + } + } + } + } + + newsTag(id: $id) { + title + path + belongsTo{ + totalCount + pageInfo { + totalPages + currentPage + } + edges { + node { + ... on News { + title + excerpt + image(width:800) + path + timeToRead + humanTime : created(format:"DD MMM YYYY") + datetime : created + author { + id + name + image(width:64, height:64, fit:inside) + path + } + }, + ... on Project { + title + excerpt + image(width:800) + path + humanTime : startdate(format:"DD MMM YYYY") + datetime : created + } } } } } + } @@ -87,10 +127,21 @@ export default { Pagination, PostListItem }, + + computed:{ + tags(){ + return this.$page.projectTag || this.$page.newsTag + }, + item(){ + var plural = this.tags.belongsTo.totalCount > 0 + return this.$page.projectTag? plural? "projects" : "project" : "news" + } + + }, metaInfo() { return { - title: "" + title: this.tags.title }; } };