lang.Merge for taxonomy pages

In a multi-lingual site, on list pages we have a simple

{{- $pages := where (.RegularPages | lang.Merge .Sites.Default.RegularPages) "Section" .Section -}}

to get all pages in the current section and “fill in” with the default (English) site ones when translations are missing.

Now, on the homepage, we want to get only a subset of the pages that have a category: categories taxonomy and show only the latest page by category:

{{- if .IsHome -}}
  {{- $homePages := slice -}}
  {{- range site.Taxonomies.categories.ByCount -}}
    {{- range first 1 .Pages -}}
      {{- $homePages = $homePages | append . -}}
    {{- end -}}
  {{- end -}}
  {{- $pages = $homePages -}}
{{- end -}}

It works well for the English site where all pages exist, but less so on translations with missing pages. How would you “fill in” the English pages for translated sites? TIA!

I don’t think it’s currently possible/practical.

That said, the next version of Hugo will, among some other things, have a revamped way of handling this that should also work for what you try to do.

1 Like

Thanks @bep !
No worries, looking forward then :wink: