How to make human url for tags?

For example I have website in german. In my post front matter, I describe

---
title: "Aktuelle Tätigkeitsberichte"
date: 2020-01-23T12:17:05+02:00
draft: false
tags: ["Lösungen"]
author: "bublick"
---

Url of this post is ok, because I have config

[permalinks]
  posts = "/:year/:month/:filename/"

But url of tag is looks like
http://localhost:1313/tags/lösungen

How can I format this to
http://localhost:1313/tags/losungen

Thank you!

Compare with my sample Site

It works for me.

Sorry für die kurze Antwort, bin gerade im Urlaub :palm_tree::cactus::sunny:

@ju52, thank you. I try to run your sample theme.

I created my german tags with ae, oe, ue and so on. Then created a file in content/tags/loesungen.md and then in that file you have the full power of frontmatter and can format the title as you want it.

@davidsneighbour, thank you, I’ve started this. I see that my tag page has a new title. But how I can print tag’s title from frontmatter, instead of beutifyied filename in my template? My template looks like

{{ with .Params.tags }}
  {{ $primaryTag := (index . 0) }}
    <section class="post-full-tags">
      <a href="{{ "/tags/" | relLangURL }}{{ $primaryTag | urlize }}">{{ $primaryTag }}</a>
    </section>
  {{ end }}

Thank you

Hmm, my template looks like yours:

But I think I told you the wrong folder structure, sorry. I have an _index.md file in folders named per tag. I have this “system” with a custom taxonomy, so I am not sure if the following works: content/tags/loesungen/_index.md and in the file then:

---
title: Lösungen
slug: loesungen
---

Title is the one shown, slug is used for the link to the taxonomy page for this tag.

By the way, you need to add this structure only for tags that you want to change, not for each single tag.

@davidsneighbour, thank you for your example. I found that folder structure don’t matter

/tags/tagname.md 
/tags/tagname/_index.md

in fact it works the same. I think that issue is related with the template which you (or me) are using. So, I decided to use simple range loop to resolve this.

<section class="post-full-tags">
    {{ range $index, $value := $.Params.tags }}
        {{ with $.Site.GetPage (printf "/tags/%s" $value) }}
            <a href="{{ .Permalink }}">{{ .Title }}</a>
        {{ end }}
    {{ end }}
</section>    

But to be honest, I need to add - this solution work only for single page. I can’t make this work on sideblocks in partials. I have no idea how to enable $.Site.GetPage in partial.

I’ve resolved this.
I’m connecting partial like

{{- partial "post-card.html" (dict "glob" $ "context" . "index" $index "home" $.IsHome) -}}

And as tag output:

{{ $glob := .glob }}
{{ range $value := .context.Params.tags }}
    {{ with $tag := $glob.Site.GetPage (printf "/tags/%s" . ) }}
        <div class="post-card-tag">{{ .Title }}</div>    
    {{ end }}
{{ end }}

I’m not sure if this is Hugo-way, so it will be nice to get a feedback from someone advanced in hugo.

1 Like