xianmin / hugo-theme-jane

A readable & concise theme for Hugo
https://xianmin.github.io/hugo-theme-jane/
MIT License
917 stars 285 forks source link

Fuse search - local fast search that's instant and accurate. (see: PaperMod theme) #370

Open ventz opened 8 months ago

ventz commented 8 months ago

Hi,

Would you consider adding Fuse search? (https://www.fusejs.io/getting-started/installation.html)

See PaperMod theme for a very simple implementation: https://github.com/adityatelange/hugo-PaperMod

There are 2 files:

Relevant section on how to use it: `PaperMod/layouts/partials/head.html

{{- /* Search */}}
{{- if (eq .Layout `search`) -}}
<link crossorigin="anonymous" rel="preload" as="fetch" href="../index.json">
{{- $fastsearch := resources.Get "js/fastsearch.js" | js.Build (dict "params" (dict "fuseOpts" site.Params.fuseOpts)) | resources.Minify }}
{{- $fusejs := resources.Get "js/fuse.basic.min.js" }}
{{- $license_js := resources.Get "js/license.js" }}
{{- if not site.Params.assets.disableFingerprinting }}
{{- $search := (slice $fusejs $license_js $fastsearch ) | resources.Concat "assets/js/search.js" | fingerprint }}
<script defer crossorigin="anonymous" src="{{ $search.RelPermalink }}" integrity="{{ $search.Data.Integrity }}"></script>
{{- else }}
{{- $search := (slice $fusejs $fastsearch ) | resources.Concat "assets/js/search.js" }}
<script defer crossorigin="anonymous" src="{{ $search.RelPermalink }}"></script>
{{- end }}
{{- end -}}
ventz commented 8 months ago

Assuming this may be an even faster approach: https://github.com/kaushalmodi/hugo-search-fuse-js

There is a good "how to" here too: https://gist.github.com/eddiewebb/735feb48f50f0ddd65ae5606a1cb41ae