From 77ff1e6b452ad64eeee5178667827323d0a1644d Mon Sep 17 00:00:00 2001 From: Aditya Telange <21258296+adityatelange@users.noreply.github.com> Date: Tue, 15 Dec 2020 18:55:01 +0530 Subject: [PATCH] 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"] --- assets/js/fastsearch.js | 1 + layouts/partials/head.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/js/fastsearch.js b/assets/js/fastsearch.js index 357867b2..e76f9193 100644 --- a/assets/js/fastsearch.js +++ b/assets/js/fastsearch.js @@ -23,6 +23,7 @@ function loadSearch() { 'content' ] }; + {{ if . }}options = {{ jsonify . }}{{ end }} // load custom options from .Site.Params.fuseOpts fuse = new Fuse(data, options); // build the index from the json file } } else { diff --git a/layouts/partials/head.html b/layouts/partials/head.html index f257b688..05837007 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -41,7 +41,7 @@ {{- if (eq .Layout `search`) -}} -{{- $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" }} {{- if not .Site.Params.assets.disableFingerprinting }} {{- $search := (slice $fusejs $fastsearch ) | resources.Concat "assets/js/search.js" | minify | fingerprint }}