-
Notifications
You must be signed in to change notification settings - Fork 284
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
feat: Added search capability via lunr (fixes #163) #165
Conversation
Awesome! I will review them asap! |
Okay, I just tested it and it works very well, except for the followings:
For the 1st, I found the following examples that look good: |
That should be easy to fix - I'll add the previous page state to the history.
What do you mean? If I set |
I tried out a multilanguage setup - multiple versions of the JS files are being generated there. So the German pages link to the German-language script which has German-language texts. What am I missing? |
Multilingual mode works well. I mean the search functionality, seems not working for Chinese. |
Maybe we can solve this by treating search link in menu as a toggle, instead of an input bar. So it will be a toggle, then click, then pop up a full screen overlay on the page, then input... But this requires lots of code refactoring. |
Oh, so lunr itself doesn't know what to do with Chinese? 😞 |
Found https://github.com/MihaiValentin/lunr-languages - that's the solution for additional lunr languages apparently. Will need to see how this can be incorporated. No Chinese however... |
Yeah, it just returns empty result... |
There is a pull request for Chinese but for some reason it's just sitting there: MihaiValentin/lunr-languages#53 Edit: Maybe the lack of progress is due to the nodejieba dependency. I don't think that this project has a good way of bundling dependencies right now. |
I added some code using History API - a new history entry is created when searching, so that the Back button brings you back to the original content. This is better than overlays, as it's the expected way for search to behave. There are some oddities here still, I'll look into this later. |
Yes, that's definitely the issue here. nodejieba is written in C++ and relies on close to 5 MB in databases. I have no idea whether there is really no simpler way of splitting a Chinese sentence into words, but this definitely isn't something that can run off the web. So, sadly, no lunr for Chinese. 😢 |
Fixed the oddities with going back and forth - the missing part was respecting What's missing now is support for non-English languages. I guess that I'll have to list the languages supported by |
Note that URL doesn't change when you search - this is intentional. I could change it to something like "#search=test" and also respect this anchor when loading. But I doubt that allowing external links to the search is a good idea. |
There we go, non-English languages will work as well now. If the language isn't supported by the lunr-languages package a warning will be printed at build time. So all done again. |
Okay, so one last issue, I will be redirected to the search page if I search on the homepage and then click on the homepage. Update: Firefox seems okay, but Chrome doesn't. |
Otherwise search box will warp to a new line.
Ok, changing URL when searching it is. Looks like no more issues now. |
Noticed an issue on an actual tablet. In landscape mode they have enough space to display the drop-down menu. But when you click the search field the virtual keyboard pops up and occupies lots of vertical screen space - search field loses focus and the menu closes. |
Reproduced. Might be a bug caused by the popped keyboard. |
Fixes reuixiy#163 * feat: Added search capability via lunr * doc: Fixed typo * chore: Updated resource files of the example site * chore: Remove unnecessary div wrapping search results * chore: Reverted change of the config documentation * chore: Ordered config entries correctly * fix: Update document title when displaying search results * fix: Handle a 404 error when downloading search index * Use menu variable for icon * Adjust search icon's style * fix: Make back button work for restoring previous page state * fix: Respect search state even when coming back from another page or site * fix: Support non-English languages * chore: port config.toml to zh-cn * i18n: add zh, pt-br translations * Increase `postWidth` and `listWidth` to `39em` Otherwise search box will warp to a new line. * Update screenshots * Update resources * fix: Update URL when searching Co-authored-by: reuixiy <[email protected]>
I've been testing this extensively and it seems to be working in all configurations. There are quite a few improvements compared to what I have on my site right now. Notes:
search
as base name - these are generic and could theoretically work unchanged with any other search provider. Others are calledlunr-search
- that's the lunr-specific code.lunr-search.js
should do for the locales that currently exist. Cyrillic languages for example have more complicated pluralization rules, but I guess that we can think about that once we actually have the issue.summaryLength
in Hugo configuration, reading out the actual value is sadly not possible.