Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search: wrong searchindex URL with multilang per server config #940

Closed
christophcemper opened this issue Oct 22, 2024 · 4 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@christophcemper
Copy link

christophcemper commented Oct 22, 2024

Great job with the theme, thanks!

We needed to remove the artifical prefixing of the language code to make this work in search.html
to even use the default _relearn_searchindex.js from the assets folder of the theme

BaseURL is https://abc.aiprm.com/AIPRM-XYZ/
Site is multilingual
However the static files are only deployed 1 time, to https://abc.aiprm.com/AIPRM-XYZ/_relearn_searchindex.js
The special case that someone deploys the same static files to language-prefixed folders cannot be default.

Also it was constructed wrong, as it ended up in https://abc.aiprm.com/en/_relearn_searchindex.js
which doesn't even sit in the same home folder/vserver on the http
and the same for all other languages.

In a 2nd line of code we had the relLangURL, which again implies the special case being default - assets in language folders and enforces the current language prefixed

here's the diff and changed file attached, not sure how to commit/add directly to repo

diff --git a/layouts/partials/search.html b/layouts/partials/search.html
index 3c5acda17c..9b1c143f48 100644
--- a/layouts/partials/search.html
+++ b/layouts/partials/search.html
@@ -11,14 +11,14 @@
{{- warnf "UNSUPPORTED usage of 'searchpage' output format found, remove it from your config; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/7/#7-0-0" }}
{{- end }}
{{- if not .Site.Params.disableSearchIndex }}

  •      {{- $url := path.Join .Site.LanguagePrefix (trim (or .Site.Params.searchIndexURL "searchindex.js") "/") }}
    
  •      {{- $url := path.Join (trim (or .Site.Params.searchIndexURL "searchindex.js") "/") }}
         {{- if .IsHome }}
           {{- $templateres := resources.Get "_relearn_searchindex.js" }}
           {{- $resultres := $templateres | resources.ExecuteAsTemplate $url .Site.Home }}
           {{- /* the following code causes Hugo to generate our file - although it is in comments */}}<!-- {{ $resultres.RelPermalink }} -->
         {{- end }}
       <script>
    
  •      window.index_js_url={{ (printf "%s%s" $url $assetBusting) | relLangURL }};
    
  •      window.index_js_url={{ (printf "%s%s" $url $assetBusting) | relURL }};
       </script>
         {{- if not .Site.Params.disableSearchPage }}
           {{- with .Site.GetPage "_relearn_searchpage" }}
    

search.html.zip

If there's a use case where people have separate static asset folders, then that would be a separate mode to implement imho,
but the default theme should work out-of-the-box imho.

Hope this helps.

christophcemper added a commit to christophcemper/hugo-theme-relearn that referenced this issue Oct 22, 2024
Related to McShelby#940

Update `search.html` to handle BaseURLs with folders correctly and remove artificial language code prefixing.

* Remove `.Site.LanguagePrefix` from the `$url` variable construction.
* Change `relLangURL` to `relURL` for `window.index_js_url`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/McShelby/hugo-theme-relearn/issues/940?shareId=XXXX-XXXX-XXXX-XXXX).
@christophcemper
Copy link
Author

Ok found the PR feature :)

@McShelby
Copy link
Owner

Thanks for the detailed bug report. Just for completeness, can you please post your hugo.toml. This helps in recreating a failing test before starting to fix and break for other configurations.

@McShelby McShelby added the needsfeedback Further information is needed label Oct 23, 2024
@McShelby
Copy link
Owner

I can not replicate this with my configuration. Please provide your hugo.toml or even better, a link to your repo.

Nevertheless, I have a vague idea why this may go wrong with your setup.

@McShelby McShelby changed the title Loading searchindexurl doesn't work with actual BaseURLs that have folders like https://abc.aiprm.com/AIPRM-XYZ/ search: wrong searchindex URL with multilang per server config Oct 24, 2024
@McShelby McShelby added bug Something isn't working and removed needsfeedback Further information is needed labels Oct 24, 2024
@McShelby McShelby added this to the 7.0.2 milestone Oct 24, 2024
@christophcemper
Copy link
Author

Thanks, just saw your q for feedback and fix, didn't get to this sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants