Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zwbetz-gh/hugo-client-side-search-template

A lightweight, fuzzy, client-side search template for Hugo
https://github.com/zwbetz-gh/hugo-client-side-search-template

fusejs

Last synced: about 1 month ago
JSON representation

A lightweight, fuzzy, client-side search template for Hugo

Awesome Lists containing this project

README

        

# Hugo client-side search template

[![Netlify Status](https://api.netlify.com/api/v1/badges/bb28781b-4732-4e74-b3de-c5f27ac37d14/deploy-status)](https://app.netlify.com/sites/hugo-client-side-search-template/deploys)

A lightweight, fuzzy, client-side search template for Hugo.

## Links

- Demo:
- Forum:

## Dependencies

Just one, [Fuse.js](https://fusejs.io/), which allows fuzzy matching, among other cool things.

## How it Works

At a high-level:

1. A JSON index is generated by hugo during the site build
1. You navigate to the deployed site
1. The DOMContentLoaded event fires
1. The JSON index is fetched
1. Fuse.js is instantiated with the JSON index
1. You do a search which fires the keyup event
1. Fuse.js is queried for hits
1. Matched substrings are highlighted (with CSS that you craft)
1. The DOM is updated with hits (with HTML that you craft)

## Relevant Files

### config.yaml

The `outputs.home` config must be set to allow JSON.

### layouts/index.json.json

Iterate all regular pages. For each page, build a dict of relevant keys, then append the dict to a slice. jsonify the slice.

### layouts/partials/scripts.html

Get the JS resource, build it, then bundle it. Put this right before your closing `