Skip to content

Commit

Permalink
fix: post meta can show custom category name
Browse files Browse the repository at this point in the history
  • Loading branch information
xianmin committed Nov 12, 2024
1 parent 5347a8f commit 535a636
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions layouts/partials/post/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,22 @@
{{ with .Params.categories -}}
<div class="post-meta-item post-meta-category">
{{ range . }}
{{- $name := . -}}
{{- with $.Site.GetPage "taxonomy" (printf "categories/%s" $name) | default ($.Site.GetPage "taxonomy" (printf
"categories/%s" ($name | urlize))) -}}
<a href="{{ .Permalink }}"> {{ $name }} </a>
{{ end -}}
{{- $category_key := lower . -}}
{{- $displayName := $category_key -}}
{{/* Get custom category name from categories.yaml */}}
{{ if index $.Site.Data "categories" }}
{{ with (index $.Site.Data.categories $category_key) }}
{{/* Handle both single language and multilingual cases */}}
{{ if reflect.IsMap .name }}
{{ $displayName = index .name $.Site.Language.Lang | default .name.default | default $category_key }}
{{ else }}
{{ $displayName = .name | default $category_key }}
{{ end }}
{{ end }}
{{ end }}
{{- with $.Site.GetPage "taxonomy" (printf "categories/%s" $category_key) -}}
<a href="{{ .Permalink }}">{{ $displayName }}</a>
{{- end -}}
{{ end }}
</div>
{{- end }}
Expand Down

0 comments on commit 535a636

Please sign in to comment.