Overview
The Hugo live search using Fuse.js and Mark.js is a theme component for the Hugo website generator. It provides live search functionality and keyword highlighting for Hugo websites.
Features
- Live search using Fuse.js
- Keyword highlighting using Mark.js
- Integration with Hugo modules
- Compatibility with Go version 1.16 and above
- Easy installation and setup
Installation
To use this theme component, follow these steps:
Add the following code to your site’s TOML config file:
[module] [[module.imports]] path = "github.com/kaushalmodi/hugo-theme-components/search"Run the following command in your main site directory to tidy the Hugo modules:
hugo mod tidyMake sure your main site repository is also a Hugo module. If it is not, run the following command in your site repo:
hugo mod init <your site url or any unique string>Create a file named
search.mdin thecontentdirectory with the following parameters:layoutset to “search”outputset to["html", "json"]
If your main theme does not meet the requirements of using base template and blocks, you may need to edit the
search.htmlpartial located in thelayouts/_defaultdirectory of this component.If your main theme does not have a
baseof.html, you have two options:- Edit the
search.htmlto fit your theme. - Upgrade your theme to use the new “base template and blocks” approach.
- Edit the
If your main theme has a
baseof.htmlbut does not have themainand/orfooterblocks, you can easily add them without breaking your existing theme. Add the following code at the appropriate place in yourbaseof.html:{{/* block "main" . */}}{{/* end */}}And add the following code if the
footerblock is missing:{{/* block "footer" . */}}{{/* end */}}
Summary
The Hugo live search theme component provides live search functionality and keyword highlighting for Hugo websites. It is easy to install and integrates seamlessly with Hugo modules. It requires Go version 1.16 or above and can be customized to fit the requirements of your main theme.