From 535a6365789ec8ab37a022e6fdc81053765e2a4f Mon Sep 17 00:00:00 2001 From: Chen Xianmin Date: Tue, 12 Nov 2024 16:12:26 +0800 Subject: [PATCH] fix: post meta can show custom category name --- layouts/partials/post/meta.html | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/layouts/partials/post/meta.html b/layouts/partials/post/meta.html index 921aba4b..230e0330 100644 --- a/layouts/partials/post/meta.html +++ b/layouts/partials/post/meta.html @@ -62,11 +62,22 @@ {{ with .Params.categories -}}
{{ range . }} - {{- $name := . -}} - {{- with $.Site.GetPage "taxonomy" (printf "categories/%s" $name) | default ($.Site.GetPage "taxonomy" (printf - "categories/%s" ($name | urlize))) -}} - {{ $name }} - {{ 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) -}} + {{ $displayName }} + {{- end -}} {{ end }}
{{- end }}