frjo / hugo-theme-zen

A fast and clean Hugo base theme with css-grid and Hugo pipes support.
https://zen-demo.xdeb.org/
GNU General Public License v2.0
264 stars 75 forks source link

The search function does not find strings on the home page(s) #98

Closed rainerhillebrand closed 1 year ago

rainerhillebrand commented 1 year ago

Dear Fredrik,

When searching for strings that are only on the home page(s) then they will not be found. The reason is the indexing with site.RegularPages in home.searchindex.json:

{{- range $index, $element := where site.RegularPages "Params.exclude_search" nil -}}

The home page and its multilingual versions are not regular pages. I solved it on my site with site.Pages:

{{- range $index, $element := where site.Pages "Params.exclude_search" nil -}}

However, this means that more pages are indexed than I would like to see in my index like "tags" and "categories". Therefore, I exclude them hard coded:

{{ if (and (ne $element.Type "tags") (ne $element.Type "categories")) }}
{{- $.Scratch.Add "searchindex" (dict "id" $index "title" $element.Title "permalink" $element.Permalink "tags" (delimit ($element.Params.tags | default "") " ") "content" $element.Plain "summary" $element.Summary "date" ($element.Date.Format ($.Param "dateformat" | default "2 January, 2006"))) -}}
{{ end }}

It's not flexible but it works. It might be more flexible to define an array for content types in hugo.toml to be excluded from indexing.

Best regards,

Rainer

frjo commented 1 year ago

I see your point but it has not been an issue on any of the sites where I use the search function.

People needing to search more than the "RegularPages" they can easily override home.searchindex.json.

I will therefor leave it as is.