search: introduce loading custom fusejs options from site config #134

* refer https://fusejs.io/api/options.html for opts
* keys used can be some, all or none from
   ["title", "permalink", "summary", "content"]

in config.yml, add fuseOpts as shown below =>
  params:
    fuseOpts:
        isCaseSensitive: false
        shouldSort: true
        location: 0
        distance: 1000
        threshold: 0.4
        minMatchCharLength: 0
        keys: ["title", "permalink", "summary", "content"]
This commit is contained in:
Aditya Telange 2020-12-15 18:55:01 +05:30
parent f9236d92af
commit 77ff1e6b45
No known key found for this signature in database
GPG Key ID: 82E844EF3DA99E77
2 changed files with 2 additions and 1 deletions

View File

@ -23,6 +23,7 @@ function loadSearch() {
'content' 'content'
] ]
}; };
{{ if . }}options = {{ jsonify . }}{{ end }} // load custom options from .Site.Params.fuseOpts
fuse = new Fuse(data, options); // build the index from the json file fuse = new Fuse(data, options); // build the index from the json file
} }
} else { } else {

View File

@ -41,7 +41,7 @@
<!-- Search --> <!-- Search -->
{{- if (eq .Layout `search`) -}} {{- if (eq .Layout `search`) -}}
<link rel="preload" as="fetch" href="../index.json" crossOrigin="anonymous"> <link rel="preload" as="fetch" href="../index.json" crossOrigin="anonymous">
{{- $fastsearch := resources.Get "js/fastsearch.js" }} {{- $fastsearch := resources.Get "js/fastsearch.js" | resources.ExecuteAsTemplate "js/fastsearch.js" .Site.Params.fuseOpts }}
{{- $fusejs := resources.Get "js/fuse.js" }} {{- $fusejs := resources.Get "js/fuse.js" }}
{{- if not .Site.Params.assets.disableFingerprinting }} {{- if not .Site.Params.assets.disableFingerprinting }}
{{- $search := (slice $fusejs $fastsearch ) | resources.Concat "assets/js/search.js" | minify | fingerprint }} {{- $search := (slice $fusejs $fastsearch ) | resources.Concat "assets/js/search.js" | minify | fingerprint }}