From 1d95c4b8ff5866dd677cc58a3de5039a12ab6915 Mon Sep 17 00:00:00 2001 From: romainx Date: Fri, 9 Oct 2020 09:49:19 +0200 Subject: [PATCH 1/3] Fix categories with special char or spaces not displayed correctly Call to [`urlize`](https://gohugo.io/functions/urlize/) to get the category url instead of using its name directly. --- layouts/partials/article/components/details.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts/partials/article/components/details.html b/layouts/partials/article/components/details.html index 016e9d6..60095de 100644 --- a/layouts/partials/article/components/details.html +++ b/layouts/partials/article/components/details.html @@ -5,7 +5,7 @@ {{ if $categories }}
{{ range $category := $categories }} - {{ $term := $.Site.GetPage (printf "/categories/%s" $category) }} + {{ $term := $.Site.GetPage (printf "/categories/%s" $category | urlize ) }} {{ if and $image.exists $image.resource }} {{- $imageRaw := $image.resource | resources.Fingerprint "md5" -}} {{- $20x := $imageRaw.Fill "20x20 smart" -}} From ddebaee028f80b475daf4478ef291dfbadd34f27 Mon Sep 17 00:00:00 2001 From: romainx Date: Fri, 9 Oct 2020 19:26:28 +0200 Subject: [PATCH 2/3] Fix tags and categories using GetTerms See [documentation](https://gohugo.io/templates/taxonomy-templates/#display-a-single-piece-of-contents-taxonomies) --- exampleSite/content/post/placeholder-text/index.md | 4 +++- layouts/partials/article/components/details.html | 12 +++++------- layouts/partials/article/components/tags.html | 9 +++------ layouts/partials/widget/tag-cloud.html | 9 +++------ 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/exampleSite/content/post/placeholder-text/index.md b/exampleSite/content/post/placeholder-text/index.md index 8ac7350..280197e 100644 --- a/exampleSite/content/post/placeholder-text/index.md +++ b/exampleSite/content/post/placeholder-text/index.md @@ -4,11 +4,13 @@ title = "Placeholder Text" date = "2019-03-09" description = "Lorem Ipsum Dolor Si Amet" categories = [ - "Test" + "Test", + "Test with whitespaces" ] tags = [ "markdown", "text", + "tag with whitespaces" ] image = "matt-le-SJSpo9hQf7s-unsplash.jpg" +++ diff --git a/layouts/partials/article/components/details.html b/layouts/partials/article/components/details.html index 60095de..0fc62e2 100644 --- a/layouts/partials/article/components/details.html +++ b/layouts/partials/article/components/details.html @@ -1,18 +1,16 @@ {{ $image := partialCached "helper/image" (dict "Context" . "Type" "article") .RelPermalink "article" }} {{- $context := . -}} -{{- $categories := .Params.categories -}}
- {{ if $categories }} + {{ if .Params.categories }} diff --git a/layouts/partials/article/components/tags.html b/layouts/partials/article/components/tags.html index 73446cd..d1261ad 100644 --- a/layouts/partials/article/components/tags.html +++ b/layouts/partials/article/components/tags.html @@ -1,10 +1,7 @@ -{{- $tags := .Params.Tags -}} -{{ if $tags }} +{{ if .Params.Tags }} {{ end }} \ No newline at end of file diff --git a/layouts/partials/widget/tag-cloud.html b/layouts/partials/widget/tag-cloud.html index a29b382..f852b4d 100644 --- a/layouts/partials/widget/tag-cloud.html +++ b/layouts/partials/widget/tag-cloud.html @@ -1,5 +1,3 @@ -{{ $tags := .Site.Taxonomies.tags.ByCount }} -
{{ (resources.Get "icons/tag.svg").Content | safeHTML }} @@ -7,10 +5,9 @@

{{ T "widgetTagCloudTitle" }}

- {{ range first .Site.Params.widgets.tagCloud.limit $tags }} - {{ $term := $.Site.GetPage (printf "/tags/%s" .Term) }} - - {{ $term.Title | humanize }} + {{ range first .Site.Params.widgets.tagCloud.limit .Site.Taxonomies.tags.ByCount }} + + {{ .Page.Title | humanize }} {{ end }}
From 1c30df93d4c501dac7717b5f023fcbac77bb470c Mon Sep 17 00:00:00 2001 From: Jimmy Cai <5889006+CaiJimmy@users.noreply.github.com> Date: Fri, 9 Oct 2020 20:08:27 +0200 Subject: [PATCH 3/3] test: add CJK taxonomy to example post --- exampleSite/content/post/chinese-test/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exampleSite/content/post/chinese-test/index.md b/exampleSite/content/post/chinese-test/index.md index f58b38f..5249ef8 100644 --- a/exampleSite/content/post/chinese-test/index.md +++ b/exampleSite/content/post/chinese-test/index.md @@ -1,11 +1,12 @@ --- -title: 中文文章内容测试 +title: Chinese Test description: 这是一个副标题 date: 2020-09-09 slug: test-chinese image: helena-hertz-wWZzXlDpMog-unsplash.jpg categories: - Test + - 测试 --- ## 正文测试