Open KaitaKoinuma opened 2 years ago
I'm having the same issue. Changing 'en'
to my site's default language is my current workaround - after that search is working for both languages (de
and en
).
Could you please share your line, @KaitaKoinuma? Simply replacing 'en'
with .Sites.First.Language.Lang
results in a syntax error for me. What did I miss?
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 @McAviti, @stdevel,
If you don't mind, I would appreciate your help testing #401.
Hi @stdevel , sorry for my late reply. I will try to check my lines after my today's work, but @onweru pull request probably help you!
@onweru Thank you for pull request for this issue and replying to stdevel and McAviti.
Hi @stdevel
I suppose that you write
const searchIndexLangSlug = pageLanguage === '{{ .Sites.First.Language.Lang }}' ? '': `${pageLanguage}/`;
and the line work as expected.
.Sites.First.Language.Lang
is surrounded by '{{ }}'
? If you did that, please show your lines.
In my source code for verfication, I also used variables.js for using first language as a const variable in search.js.
variable.js
const defaultContentLanguage = '{{ .Sites.First.Language.Lang }}';
search.js
const searchIndexLangSlug = pageLanguage === defaultContentLanguage ? '': `${pageLanguage}/`;
Hi @McAviti, @stdevel,
If you don't mind, I would appreciate your help testing #401.
@onweru -- did a run with branch <371-fix-search-index-lookup>, and it worked for default lang german -- thank you!
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 messageGET http://localhost:1313/{lang code}/index.json 404 (Not Found)
.Relevant log output
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.toml I 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!