From e5ae1d696ba1a7327431e3c97b3cc30dbb6a9d94 Mon Sep 17 00:00:00 2001 From: "W.T. Chang" Date: Mon, 18 May 2020 17:30:37 +0800 Subject: [PATCH] fix(path): broken tag/category link when containing a dot (#368) --- layouts/_default/summary.html | 6 +++--- layouts/partials/function/path.html | 3 +++ layouts/partials/single/footer.html | 2 +- layouts/posts/single.html | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 layouts/partials/function/path.html diff --git a/layouts/_default/summary.html b/layouts/_default/summary.html index fa990e1..da1e819 100644 --- a/layouts/_default/summary.html +++ b/layouts/_default/summary.html @@ -31,7 +31,7 @@ {{- $categories := slice -}} {{- range .Params.categories -}} - {{- $category := . | anchorize | printf "/categories/%v" | $.Site.GetPage -}} + {{- $category := partialCached "function/path.html" . . | printf "/categories/%v" | $.Site.GetPage -}} {{- $categories = $categories | append (printf `%v` $category.RelPermalink $category.Title) -}} {{- end -}} {{- with delimit $categories " " -}} @@ -58,10 +58,10 @@   {{- range $index, $value := . -}} {{- if gt $index 0 }}, {{ end -}} - {{- $tag := $value | anchorize | printf "/tags/%v" | $.Site.GetPage -}} + {{- $tag := partialCached "function/path.html" $value $value | printf "/tags/%v" | $.Site.GetPage -}} {{ $tag.Title }} {{- end -}} {{- end -}} - + \ No newline at end of file diff --git a/layouts/partials/function/path.html b/layouts/partials/function/path.html new file mode 100644 index 0000000..ece426f --- /dev/null +++ b/layouts/partials/function/path.html @@ -0,0 +1,3 @@ +{{- /* https://discourse.gohugo.io/t/how-decode-urls-in-hugo/7549/4 */ -}} +{{- $URL := . | urlize | urls.Parse -}} +{{- return $URL.Path -}} diff --git a/layouts/partials/single/footer.html b/layouts/partials/single/footer.html index 36d6fe3..c5b682f 100644 --- a/layouts/partials/single/footer.html +++ b/layouts/partials/single/footer.html @@ -51,7 +51,7 @@   {{- range $index, $value := . -}} {{- if gt $index 0 }}, {{ end -}} - {{- $tag := $value | anchorize | printf "/tags/%v" | $.Site.GetPage -}} + {{- $tag := partialCached "function/path.html" $value $value | printf "/tags/%v" | $.Site.GetPage -}} {{ $tag.Title }} {{- end -}} {{- end -}} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index ab5f4da..feeefaa 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -39,7 +39,7 @@ {{- $categories := slice -}} {{- range .Params.categories -}} - {{- $category := . | anchorize | printf "/categories/%v" | $.Site.GetPage -}} + {{- $category := partialCached "function/path.html" . . | printf "/categories/%v" | $.Site.GetPage -}} {{- $categories = $categories | append (printf `%v` $category.RelPermalink $category.Title) -}} {{- end -}} {{- with delimit $categories " " -}}