taxonomy: fix sorting of terms on content pages #710

This commit is contained in:
Sören Weber 2023-11-01 22:19:39 +01:00
parent ec482bb3de
commit 4ebb6d9eac
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D

View file

@ -13,19 +13,20 @@
{{- end }} {{- end }}
{{- $taxonomy_page := $page.Site.GetPage $taxonomy }} {{- $taxonomy_page := $page.Site.GetPage $taxonomy }}
{{- $terms := slice | append (index $page.Params $taxonomy) }} {{- $terms := slice | append (index $page.Params $taxonomy) }}
{{- $term_pages := dict }} {{- $term_pages := slice }}
{{- range sort $terms }} {{- range $terms }}
{{- $term := trim . " " }} {{- $term := trim . " " }}
{{- if not $term }} {{- if not $term }}
{{- continue }} {{- continue }}
{{- end }} {{- end }}
{{- $term_key := ($term | plainify | anchorize) }} {{- $term_key := ($term | plainify | anchorize) }}
{{- with $page.Site.GetPage (printf "%s/%s" $taxonomy $term_key) }} {{- with $page.Site.GetPage (printf "%s/%s" $taxonomy $term_key) }}
{{- $term_pages = $term_pages | merge (dict $term_key .) }} {{- $term_pages = $term_pages | append (dict "Title" (default .Data.Term .Title) "Term" . )}}
{{- end }} {{- else }}
{{- $term_key = ($term | urlize) }} {{- $term_key = ($term | urlize) }}
{{- with $page.Site.GetPage (printf "%s/%s" $taxonomy $term_key) }} {{- with $page.Site.GetPage (printf "%s/%s" $taxonomy $term_key) }}
{{- $term_pages = $term_pages | merge (dict $term_key .) }} {{- $term_pages = $term_pages | append (dict "Title" (default .Data.Term .Title) "Term" . )}}
{{- end }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- with $term_pages }} {{- with $term_pages }}
@ -34,9 +35,9 @@
<i class="{{ $icon }}"></i> <i class="{{ $icon }}"></i>
{{- end }} {{- end }}
<ul> <ul>
{{- range $term_page := . }} {{- range sort . ".Title" }}
{{- $to := . }} {{- $to := .Term }}
<li><a class="term-link" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" $to) }}">{{ default $to.Data.Term $to.Title }}</a></li> <li><a class="term-link" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" $to) }}">{{ .Title }}</a></li>
{{- end }} {{- end }}
</ul> </ul>
</div> </div>