-
Notifications
You must be signed in to change notification settings - Fork 265
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
[Bug] Search function doesn't work when the default language is other than 'en'. #371
Comments
I'm having the same issue. Changing Could you please share your line, @KaitaKoinuma? Simply replacing |
Ahoj @stdevel -- I also did not know the correcty way to refer to the first language, so my workaround was was to replace hardcoded "en" with hardcoded "de", that acchieved the same result. |
Hi @stdevel I suppose that you write
and the line work as expected.
In my source code for verfication, I also used variables.js for using first language as a const variable in search.js. variable.js
search.js
|
I also tried #401 with Chinese, it works fine so far. |
Thanks for the feedback @Sciroccogti and @McAviti . Will merge. |
I confirm:
Hugo version
0.101.0
Where is this bug showing up?
In the browser: Hugo builds the site, but something doesn't look right.
Operating system
Ubuntu 20.04
Browser (if applicable)
Chrome 103
Current behavior
For example, if swith DefaultContentLanugage to 'pt' from 'en', search function does not work because Lang prefix is attached to index.json for no-en language and cannot be loaded.
Expected behavior
When load index.json, lang prefix is not attached to it when default language but it is attached to when sub languages.
Steps to reproduce
Set 'DefaultContentLanguage' in config.toml to no-en language and restart
hugo server
and search function does not work.Please look DevTool and it display error message
GET http://localhost:1313/{lang code}/index.json 404 (Not Found)
.Relevant log output
GET http://localhost:1313/{lang code}/index.json 404 (Not Found) SyntaxError: Unexpected token p in JSON at position 4
Related code
https://github.com/chipzoller/hugo-clarity/blob/master/assets/js/search.js
line:230-234
Preferred solution
In the above code, compare pageLanguage with the hard coded 'en', but should be compare with the dynamic default language variable.
As one solution, I propose using
.Sites.First.Language.Lang
instead of hard corded 'en' because I cannot find way to get DefaultContentLanguage from config.tomlI don't feel good about that this solution force users to set default language weight in languages.toml to 1, but I could think of no other way.
I confimed that this solution works succesfully in my environment.
Other information
I hope this report help other people.
Thanks!
The text was updated successfully, but these errors were encountered: