Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/balaramadurai/hugo-travelify-theme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandip Bhattacharya <sandipb@showmethesource.org>2020-09-13 02:30:47 +0300
committerSandip Bhattacharya <sandipb@showmethesource.org>2020-09-13 02:30:47 +0300
commit0b15ddaa9b8e94d2f36959973f7c2405d09fed93 (patch)
tree5906275946da0275ed25e64afa91cd98de2083c0
parent63c19cfdd644ff1e576a2135903af1c8adfe017f (diff)
Links to tags/categories now respect permalink configuration
Blog configuration can be modified to have different link permalink layout. e.g. in the `[permalinks]` section, categories can be set up in these different ways: - `categories = "/category/:slug/"` - `categories = "/categories/:slug/"` The widgets for categories and tag_cloud were hardcoding the permalinks URL. This fix will make the URL respect permalink configuration. Inspired from this hugo forum conversation: https://discourse.gohugo.io/t/how-to-get-permalink-of-taxonomies-in-templates/12927/15
-rw-r--r--layouts/partials/widgets/categories.html5
-rw-r--r--layouts/partials/widgets/tag_cloud.html4
2 files changed, 6 insertions, 3 deletions
diff --git a/layouts/partials/widgets/categories.html b/layouts/partials/widgets/categories.html
index 12f49fd..058e779 100644
--- a/layouts/partials/widgets/categories.html
+++ b/layouts/partials/widgets/categories.html
@@ -2,10 +2,11 @@
<h3 class="widget-title">{{with .Site.Data.l10n.widgets.categories.title}}{{.}}{{end}}</h3>
<ul>
{{ range $name, $items := .Site.Taxonomies.categories }}
+ {{ with site.GetPage (printf "/%s/%s" "categories" $name) }}
<li class="cat-item">
- {{ $url := printf "%s/%s" "categories" ($name | urlize)}}
- <a href="{{ $url | absURL }}">{{ $name | title }}</a> ({{ len $items }})
+ <a href="{{ .Permalink }}">{{ $name | title }}</a> ({{ len $items }})
</li>
{{ end }}
+ {{ end }}
</ul>
</aside>
diff --git a/layouts/partials/widgets/tag_cloud.html b/layouts/partials/widgets/tag_cloud.html
index 21cdb8d..236dfdb 100644
--- a/layouts/partials/widgets/tag_cloud.html
+++ b/layouts/partials/widgets/tag_cloud.html
@@ -9,12 +9,14 @@
{{ $baseurl := .Site.BaseURL }}
{{ range $name, $value := .Site.Taxonomies.tags }}
{{ if (gt $value.Count $min_count) }}
- <a href="{{ $baseurl }}tags/{{ $name | urlize }}" style="font-size: {{ add ($value.Count) $mag_factor }}px;" title="{{ ($value.Count) }} topics">
+ {{ with site.GetPage (printf "/%s/%s" "tags" $name) }}
+ <a href="{{ .Permalink }}" style="font-size: {{ add ($value.Count) $mag_factor }}px;" title="{{ ($value.Count) }} topics">
<!--a href="{{ $baseurl }}/tags/{{ $name | urlize }}"-->
{{ $name | title }}
</a>
{{ end }}
{{ end }}
+ {{ end }}
</div>
</aside>