Make /tags/... available at /tag?

With Hugo (0.55.5) and the ghostwriter theme, the tag index is available at /tags/ and individual tag listings are available at /tags/<sometag>/ (e.g., /tags/hugo/). In order to preserve URLs from my old blog, I would like the same content to be available at /tag/ and /tag/<sometag>/. What’s the best way to go about that?

I can add an alias to content/tags/_index.md, but this only takes care of the tag index, not individual tags.

I’d be happiest just relocating /tags/ to /tag/, which would match the use of the singular /post/ for post URLs.

…I realize that I could do something like this:

taxonomies:
  tag: tag

…and then modify all the existing content to use tag, singular, in the front matter, rather than tags. This is my fallback if there’s not a mechanism available to control the URL independently.

Hi there!

I do it the Hugo way and use tags in front matter. But I change permalinks for each taxonomy page.

config.toml:

[permalinks]
tags = "/tag/:slug/"

So you have /tags/ as taxonomyTerm, but e.g. /tag/my-tag for taxonomy.

Thanks. I was just starting to experiment with that. The problem I have now is that the theme I’m using hardcodes the tag path as /tags/, and while I can just modify the theme it would be great if there were a way for it to generate tag URLs that took the permalink configuration into account.

In Hugo 0.55.0 and above you no longer have to hard code /tags/ as you mentioned, as you can use the page permalink. Here’s the example given in the release notes

<ul>
  {{ range .Data.Terms.Alphabetical }}
    <li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
  {{ end }}
</ul>

I’m confused: .Page.Permalink is going to give the permalink for the current page, not for a given tag. I’m trying to replace something like this in a post template:

<p class="post-tags">
    <span>Tagged:</span>
    {{ $len := len .Params.tags }}
    {{ range $index, $tag := .Params.tags }}
        <a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}/">{{ . }}</a>
        {{- if lt $index (sub $len 1) -}}, {{ end }}
    {{ end }}
</p>

Based on some help in another thread, it looks as if this was the solution:

        <p class="post-tags">
            <span>Tagged:</span>
            {{ $len := len .Params.tags }}
            {{ range $index, $tag := .Params.tags }}
              {{ $term := . }}
              {{ with $.Site.GetPage (printf "/%s/%s" "tags" $term) }}
              <a href="{{ .Permalink }}">{{ $term }}</a>
                {{- if lt $index (sub $len 1) -}}, {{ end }}
              {{ end }}
            {{ end }}
        </p>

I see now. I thought you were working in a terms template at first. In that case use @kaushalmodi’s example here How to get permalink of Taxonomies in templates?