adityatelange / hugo-PaperMod

A fast, clean, responsive Hugo theme.
https://adityatelange.github.io/hugo-PaperMod/
MIT License
10.26k stars 2.72k forks source link

[Enhancement]: Display Tags for Multilingual Posts #1632

Open cozyan opened 4 days ago

cozyan commented 4 days ago

What you'd like to propose?

In the current demo, when navigating to related posts, the following tags are displayed:

image

However, when you switch to /fr and then click a post, for example on this page, no tags are listed:

image

The reason is that in themes/PaperMod/layouts/_default/single.html, we only allow .Language.Params.Taxonomies.tag as defined in config.yml. I think it would be better to allow dynamic tags for different language pages.

For example, in my current setup, I switched to the following code:

<footer class="post-footer">
    {{- if eq .Lang "en" }}
        {{- if .Params.tags }}
        <ul class="post-tags">
            {{- range (.GetTerms "tags") }}
            <li><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
            {{- end }}
        </ul>
        {{- end }}
    {{- else if eq .Lang "cn" }}
        {{- with .Params.cntags }}
        <ul class="post-tags">
            {{- range . }}
            <li><a href="/cn/cntags/{{ . | urlize }}">{{ . }}</a></li>
            {{- end }}
        </ul>
        {{- end }}
    {{- end }}
    {{- if (.Param "ShowPostNavLinks") }}
    {{- partial "post_nav_links.html" . }}
    {{- end }}
    {{- if (and site.Params.ShowShareButtons (ne .Params.disableShare true)) }}
    {{- partial "share_icons.html" . -}}
    {{- end }}
</footer>

This code allows me to display tags under both English posts and Chinese posts.

Expected Behavior

Tags should appear under the post for the selected language.

Actual Behavior

Tags are not displayed for posts in non-default languages.

Code of Conduct