]> juplo.de Git - website/commitdiff
thymeleaf-theme: Reworked partial `terms.html`
authorKai Moritz <kai@juplo.de>
Sun, 30 Nov 2025 08:11:06 +0000 (09:11 +0100)
committerKai Moritz <kai@juplo.de>
Wed, 3 Dec 2025 20:22:02 +0000 (21:22 +0100)
hugo/themes/thymeleaf/layouts/_partials/terms.html
hugo/themes/thymeleaf/layouts/page.html

index 8a6ebec2a2cc3967aca21a8d253b130c17fa8d8e..550ed41a83c243162a4f67c556da34ca0352c49c 100644 (file)
@@ -1,23 +1,13 @@
-{{- /*
-For a given taxonomy, renders a list of terms assigned to the page.
-
-@context {page} page The current page.
-@context {string} taxonomy The taxonomy.
-
-@example: {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
-*/}}
-
-{{- $page := .page }}
-{{- $taxonomy := .taxonomy }}
-
-{{- with $page.GetTerms $taxonomy }}
-  {{- $label := (index . 0).Parent.LinkTitle }}
-  <div>
-    <div>{{ $label }}:</div>
-    <ul>
-      {{- range . }}
-        <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
-      {{- end }}
-    </ul>
-  </div>
+{{- $page := .Page }}
+{{- range .Page.Site.Taxonomies }}
+{{- $taxonomy := . }}
+{{- $terms := $page.GetTerms .Page.Data.Plural }}
+{{- if gt $terms.Len 0 }}
+<h3><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a></h3>
+<ul>
+  {{- range $terms }}
+  <li><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> <span>{{ $taxonomy.Count .Page.Data.Term }}</span></li>
+  {{- end }}
+</ul>
+{{- end }}
 {{- end }}
index 7e286c80218e935af6181f62bdcc83f5fd9b197f..1f53ceb94f7460cd498e9e6423ea5f5b8b426a89 100644 (file)
@@ -6,5 +6,5 @@
   <time datetime="{{ $dateMachine }}">{{ $dateHuman }}</time>
 
   {{ .Content }}
-  {{ partial "terms.html" (dict "taxonomy" "tags" "page" .) }}
+  {{ partial "terms.html" . }}
 {{ end }}