yihui / hugo-prose

A Hugo theme derived from the XMin theme, and inspired by Wowchemy, Distill, and tufte.css
https://prose.yihui.org
MIT License
97 stars 13 forks source link

Enable site-wide search #9

Closed apreshill closed 4 years ago

apreshill commented 4 years ago

Distill recently added this via fuse.js based on feature requests, and the new RStudio blog (a blogdown site built with a custom Hugo theme) will have it too via lunr.js.

This is very hard to add on your own, and is now a big differentiator for users to make the choice between Distill/bookdown and blogdown (one of the reasons I use the academic theme for teaching).

See:

https://github.com/rstudio/rstudio.com/pull/156/commits/026af8566fc1d3c3b6eee6d1a686f8551bec3b73

https://palant.info/2020/06/04/the-easier-way-to-use-lunr-search-with-hugo/

jienagu commented 4 years ago

Here is my two cents: https://github.com/bvaughn/js-search This is a client side light js search library.

apreshill commented 4 years ago

That looks interesting- thank you for sharing! I cannot really evaluate relative dependencies, but fuse.js says also "Fuse.js is a powerful, lightweight fuzzy-search library, with zero dependencies" and "Simplicity and performance were the main criteria when developing this library." If we use fuse.js here, the search interface would be same across the new bs4_book bookdown output format and distill's website, which is nice for users to have a common interface and experience 🌟

yihui commented 4 years ago

FYI I had figured out all pieces of information that I need yesterday (thanks to the super helpful notes by @apreshill), but I was interrupted later so didn't manage get it done. This is not technically challenging for me to implement now, but I do need some time (and also a good mood these days).

yihui commented 4 years ago

Done. There may be a few rough edges but I think it's mostly working now: https://prose.yihui.org Click "Search" in the menu (it works on any page that has this menu), and type in the box to search. For an average site, it should be fairly fast. I tested with my own posts, too, and there was a delay of one or two seconds after typing, but I guess not many people have thousands of posts on their sites :)

apreshill commented 4 years ago

Looks beautiful!