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.
…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.
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>