Listing json file with all pages across translations

I’m trying to have a /index.json file to use with algolia that includes all pages, regardless of their Language.

Searching the forum I found a few mentions to .Site.AllRegularPages and the documentation also shows .Site.AllPages as an option. However that still only returns the pages for the current language.

Any idea on what I may be missing?

{{- $.Scratch.Add "index" slice -}}
{{- range where (where .Site.AllPages ".Params.options" "!=" nil ) ".Params.options.unlisted" "!=" true -}}
{{- $image := .Resources.GetMatch "header" -}}
{{- if  $image -}}
	{{- $thumbnail := $image.Fill "450x150" -}}
	{{- $.Scratch.Add "index" (dict "title" .Title "subtitle" .Params.subtitle "ref" .Permalink "tags" .Params.tags "content" .Plain "image" $thumbnail.Permalink) -}}
{{- else -}}
	{{- $.Scratch.Add "index" (dict "title" .Title "subtitle" .Params.subtitle "ref" .Permalink "tags" .Params.tags "content" .Plain "image" "" ) -}}
{{- end -}}
{{- end -}}
{{- $.Scratch.Get "index" | jsonify -}}```

Not exactly what you’re trying to do, but these examples may be helpful: Fetch page from another language using .GetPage

Thinking way back, when I was setting up a bilingual site, I wanted a combined set of tags, which I never figured out how to do. I’m interested in this as well, if indirectly.

In case there is no hugo solution, you might be able to script something to grab the files from generated sites, and merge them before feeding the result to algolia. If I were trying it, I would try it with jq.

Are you really sure about that? That seems like an odd bug to have slipped through the tests (create a GH issue if you are really sure)

That said, you can also do something ala:

{{ range .Sites }}
{{ $pages := .RegularPages }}
{{ end }}

Guys thank you for your help.

It turns out that I had two index.json files, one in the theme folder and another in /layouts/index.json
I found that out when I was preparing a test site to include in the github issue.

.Site.AllRegularPages works as expected.

Sorry for wasting your time :man_facepalming:

1 Like

As an added note, I would recommend using append to create search lists like in the above. The .Scratch construct looks a little clumsy now that Go template supports variable overwrites.


(tried it here: Switching from scratch to append for a search index)

1 Like