Why does Hugo generate different taxonomy-related HTML on different OS's?

34 Views Asked by At

I have modified the Ananke theme for Hugo for my own purposes, the modifications are here.

The key change was that I wanted a list of linkable tags (that the theme already put at the bottom of every post) to also appear at the top of the /tags/ page (and also do the same for categories and other taxonomies). In addition, I wanted a count of applicable posts to also show in each tag bubble.

So, I put this code into the template /layouts/_default/terms.html:

 {{ $taxonomyObject := cond (eq .Data.Plural "tags") .Site.Taxonomies.tags .Site.Taxonomies.categories }}
<div class="measure-wide-l center f4 lh-copy nested-copy-line-height nested-links {{ $.Param "text_color" | default "mid-gray" }}">
  {{ .Content }}
  <ul class="pa0">
    {{ range .Data.Pages }}
     <li class="list di">
       <a href="{{  .Page.RelPermalink }}" class="link f5 grow no-underline br-pill ba ph3 pv2 mb2 dib black sans-serif">
         {{- .Page.Title -}} <span class="f4"><strong> {{ $taxonomyObject.Count .Page.Title }}</strong></span>
       </a>
     </li>
    {{ end }}
  </ul>
</div>

(I can add checks for taxonomies other than tags and categories later)

I've also modified the exampleSite category to add some tags and categories. However, unlike what most examples and tutorials show, I didn't make all of them single-word lowercase values (if I had, I wouldn't have noticed the issue).

Here's what the result looks like on macOS (Sonoma 14.4.1, Intel, go v1.22.1, Hugo v0.124.1):

Tags-Mac Categoris-Mac

And here's the what Hugo generates from the same source on Linux (Alpine 3.18, x86_64, go v1.20.11, Hugo v0.111.3)

Tags-Linux Categories-Linux

The differences are, as you see:

  • On Linux, the taxonomy titles are displayed exactly as they are in the source -- capitalized only if the source is capitalized. MacOS applies "Book Title" capitalization rules (words other than a, the, and, etc are capitalized).
  • If the taxonomy is capitalized or has a space in the title, the count on Linux is 0.

I see the latter as a more egregious problem than the former, but it'd be nice if all behavior was consistent across OS's.

A part of the solution I've found involves modifying the template entry as follows:

<li class="list di">
       {{ $normalizedTerm := replace (lower .Page.Title) " " "-" }}
       <a href="{{  .Page.RelPermalink }}" class="link f5 grow no-underline br-pill ba ph3 pv2 mb2 dib black sans-serif">
         {{- .Page.Title -}} <span class="f4"><strong> {{ $taxonomyObject.Count $normalizedTerm }}</strong></span>
       </a>
     </li>

However, if I just change to that, the count will be incorrect on macOS.

So why does this happen, and how do I get consistent site generation regardless of what OS I'm doing it from? I don't see a way to determine the OS type inside the template in the Hugo docs (somewhat relevant functionality is here and here. And even if that was possible, it's hardly an ideal solution:

  • this could be due to different Hugo versions
  • this could be specific to the distro/version of Linux I'm using

While one obvious difference is that the Linux file system is case-sensitive, it's not that straightforward, since all files Hugo generates are lowercased without spaces, on both systems. Hugo really generates different HTML from the same code, depending on OS.

So, the two questions are:

  1. Why?
  2. What do I change to get the same HTML?
0

There are 0 best solutions below