mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 23:38:56 +00:00
fix: improve fuse search config for multilingual support (#639)
Refactored fuse search configuration logic to dynamically resolve fuseIndexURL based on current language context. Replaced static .RelPermalink assignment with conditional logic that handles translated pages. Introduced logic to determine config.js path based on whether the current page is a regular content page or a language root. - For regular pages: config.js is placed under the page's permalink. - For non-regular pages: config.js is resolved using the language prefix. This ensures correct search index loading in multilingual Hugo sites.
This commit is contained in:
@@ -33,8 +33,17 @@ FixIt theme assets partial
|
||||
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}}
|
||||
{{- $config = dict "type" "algolia" "algoliaIndex" $search.algolia.index "algoliaAppID" $search.algolia.appID "algoliaSearchKey" $search.algolia.searchKey | dict "search" | merge $config -}}
|
||||
{{- else if eq $search.type "fuse" -}}
|
||||
{{- $searchURL := "" -}}
|
||||
{{- with .Site.Home.OutputFormats.Get "search" -}}
|
||||
{{- $config = dict "type" "fuse" "fuseIndexURL" .RelPermalink | dict "search" | merge $config -}}
|
||||
{{- $searchURL = .RelPermalink -}}
|
||||
{{- end -}}
|
||||
{{- if .IsTranslated -}}
|
||||
{{- with .OutputFormats.Get "search" -}}
|
||||
{{- $searchURL = .RelPermalink -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $searchURL -}}
|
||||
{{- $config = dict "type" "fuse" "fuseIndexURL" $searchURL | dict "search" | merge $config -}}
|
||||
{{- end -}}
|
||||
{{- $source := $cdn.fuseJS | default "lib/fuse/fuse.min.js" -}}
|
||||
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}}
|
||||
@@ -311,6 +320,9 @@ FixIt theme assets partial
|
||||
{{- $targetPath := "js/config.js" -}}
|
||||
{{- if in .Site.RegularPages .Page -}}
|
||||
{{- $targetPath = $noBaseRelPermalink | printf "%s/config.js" -}}
|
||||
{{- else -}}
|
||||
{{- $langPrefix := strings.TrimPrefix "/" (relLangURL "") -}}
|
||||
{{- $targetPath = printf "%sjs/config.js" $langPrefix -}}
|
||||
{{- end -}}
|
||||
{{- dict "Content" $configJS "Path" $targetPath "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user