I’m a bit lost in Hugo’s templating rules. I have blog posts under /content/blog/ so they appear at <base_url>/blog/... - which is what I want.
Is it possible to have tags also nested under blog, i.e. the term page would then be at <base_url>/blog/tags/ and list pages at <base_url>/blog/tags/<my_tag>/ ?
Thanks @zwbetz, it worked out for the list pages, however not for the terms page, it’s still at ROOT/tags/. Should I then add an _index.md and set a URL manually, or is there a better way?
I’ve sorted it out. The only changes required were:
Set tags = "/blog/tags/:title/" in the Permalinks section of the site config file
Create a file /content/blog/tags/_index.md with the following front matter:
title: Blog tags
type: tags
layout: terms
# The below creates a redirect at /tags to this page.
# Not really required but neat
aliases:
- /tags
Use .Site.Taxonomies.tags instead of .Data.Terms in the terms template (/layout/tags/terms.html)
In order for aliases from the front matter to work, you need to disable default page generation at /tags because it will overwrite the redirect page otherwise. The simplest way to achieve that I managed to find is to create an empty template file /layouts/tags/empty.html and configure the page at /tags to use it by creating /content/tags/_index.md with the following content:
Good deal. And for clarity for future readers: Point (1) sets the permalink of individual tags pages. Points (2) and (3) set the permalink of the tags list page.
There’s still one problem though. I see that tag terms and lists get now generated in both /tags/ and /blog/tags/, effectively duplicating all pages. Also peculiar that all links on both terms pages point at the correct tags under /blog/tags/.
I think I’ve figured that out. I’ve updated my solution post.
On a side note, IMHO it would be nice to have a simpler/cleaner way of reconfiguring taxonomy URLs.