I am trying to implement a search function into my multilingual HUGO site, however, the simplest step proved to be not as simple as expected.
I have created a JSON file with this path /layouts/_default/search.json, and it looks like this:
[
{{- range .Site.RegularPages -}}
{
"link": "{{ .RelPermalink }}",
"title": "{{ .Title }}",
"type": "{{ .Params.type }}",
"search": "{{ .Params.search }}",
"show": "{{ .Params.search }}"
}
{{- if not (last .Site.RegularPages) -}},{{- end -}}
{{- end -}}
]
Now, I tried to access the JSON file in my JS (it’s not complete yet, I’ve stopped to troubleshoot), saved in /static/js/search.js and referenced in my head partial. This is the JS code:
Remove the layout key/value pair from front matter. Specify this value only when you need to override the template lookup order. Currently you have layout: single on content/en/articles/_index.md (a list page), which doesn’t make any sense.
Remove the type key/value pair from front matter. Specify this value only when you need to override the page type inferred from the top level directory name.
Layouts
Use the base/block structure to simplify your templates.
Create layouts/_default/list.html to handle section pages.
Site configuration: deprecated custom parameters on the language key
This multilingual scaffold/example might be helpful:
git clone --single-branch -b hugo-forum-topic-45534 https://github.com/jmooring/hugo-testing hugo-forum-topic-45534
cd hugo-forum-topic-45534
hugo server
I only fixed the [outputs] issue and I will leave everything else as is, it works fine now. The search also works. I will be making the repo private soon, so I could work further on my site without everybody looking. Thank you anyway.