gethugothemes / hugo-modules

30+ Powerful Hugo Modules Created By Gethugothemes.
https://gethugothemes.com/hugo-modules
MIT License
111 stars 49 forks source link

Search module does not display page bundle images #19

Closed aleixripoll closed 10 months ago

aleixripoll commented 1 year ago

Search module only displays images with absolute URLs, the context is not sent to thesearchImage partial so it uses the default "dot":

https://github.com/gethugothemes/hugo-modules/blob/c3e6f1eb8b7b49571bf0d102cd2647beac1b5937/search/layouts/_default/list.searchindex.json#L20-L28

For page bundles, Context must be set to .Page:

{{- if .Params.image -}}
  {{- $.Scratch.Set "image" (partial "searchImage" (dict "Context" .Page "Src" .Params.image "Size" "420x" "Command" "Resize")) -}}
  {{- $.Scratch.Set "imageSM" (partial "searchImage" (dict "Context" .Page "Src" .Params.image "Size" "100x100" "Command" "Fill")) -}}
{{- else if .Params.images -}}
  {{- range first 1 .Params.images -}}
  {{- $.Scratch.Set "image" (partial "searchImage" (dict "Context" .Page "Src" . "Size" "420x" "Command" "Resize")) -}}
  {{- $.Scratch.Set "imageSM" (partial "searchImage" (dict "Context" .Page "Src" . "Size" "100x100" "Command" "Fill")) -}}
  {{- end -}}
{{- end -}}
tfsomrat commented 1 year ago

hey @aleixripoll you can create a PR, and contribute to this awesome search module.