HTML links for Tags and Categories

For offline documentation purposes, I need to have URLs that are both relative and ugly (end in .html).

My current hack is:

In config.toml, define:

relativeURLs = "true"
uglyURLs = "true"
[params]
    # set to "" if uglyURLs = "false"
    # set to ".html" if uglyURLs = "true"
    ugly = ".html"

Then, where I need a list of categories:

{{ if isset .Params "categories" }}
  {{ range .Params.categories }}
    <a href="{{ delimit (slice "/categories/" (urlize .) $.Site.Params.ugly) "" | relURL }}">Category: {{ . }}</a>
  {{ end }}
{{ end }}

Which is:

  • slice : make a slice containing three strings
  • delimit : join those strings together using the string "" (the empty string)
  • | relURL : make the whole mess relative.

I wouldn’t really call this elegant.

What’s the type of the elements in .Params.categories ? It would be neat if it supported a .URL property:

<!-- Note: This doesn't work. -->
{{ if isset .Params "categories" }}
  {{ range .Params.categories }}
    <a href="{{ .URL }}">Category: {{ . }}</a>
  {{ end }}
{{ end }}