mirror of https://github.com/luizdepra/hugo-coder.git

si-kui-a
yesterday f5534bfb9ca8c8c22a4124c6a3629d54513c307e
fix(series): look up multi-word series names via Taxonomy.Get, not anchorize (#1011)

Fixes #980.

`layouts/_partials/posts/series.html` looked up a series' pages by
running the front-matter value through `anchorize` (`"Some Series Name
with Spaces"` → `"some-series-name-with-spaces"`) and indexing
`$.Site.Taxonomies.series` with that hyphenated string. Hugo's own
`Taxonomy.Get` (`resources/page/taxonomy.go` in Hugo core) only
lowercases the key - it doesn't hyphenate it - so the real map key for a
multi-word term is `"some series name with spaces"` (lowercase, spaces
intact). Any series name with more than one word therefore never
matched, and the whole "See also in ..." block silently rendered
nothing, exactly as your debug output in the issue showed.

Swapped the manual `anchorize` + `index` for
`$.Site.Taxonomies.series.Get .` (the built-in accessor, which does the
correct lowercase-only normalization) - same `WeightedPages` return
type, so `$series.Pages` and everything after it is untouched. The other
two `anchorize` calls in the file are for the heading's HTML `id`/anchor
link, a genuinely different purpose (URL-safe fragment), so I left those
alone.

Verified by actually building the exampleSite through the theme (not
just reading the template): added two posts sharing `series: ["Some
Series Name with Spaces"]`, confirmed the unmodified template really
does render an empty `<section class="see-also">` with no heading or
link (reproducing the bug), then confirmed the fix produces `<h3>See
also in Some Series Name with Spaces</h3>` with a working link to the
sibling post.

Co-authored with Claude Code (Anthropic); reviewed by @si-kui-a before
submission.

Co-authored-by: lilichen-F <147837261+lilichen-F@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
1 files modified
6 ■■■■■ changed files
layouts/_partials/posts/series.html 6 ●●●●● patch | view | raw | blame | history
layouts/_partials/posts/series.html
@@ -2,8 +2,10 @@
{{ if .Params.series }}
<section class="see-also">
  {{ range .Params.series }}
    {{ $name := . | anchorize }}
    {{ $series := index $.Site.Taxonomies.series $name }}
    {{/* Hugo's taxonomy map key is the lowercased term (see Taxonomy.Get), not the
      anchorized/hyphenated form - looking it up via `anchorize` silently failed to
      find multi-word series names containing spaces (#980). */}}
    {{ $series := $.Site.Taxonomies.series.Get . }}
    {{ if gt (len $series.Pages) 1 }}
      <h3 id="{{ i18n "see_also" | default "See also in" | anchorize }}-{{ anchorize . | safeURL }}">
        {{ i18n "see_also" | default "See also in" }} {{ . }}