From dcd5dd0ec9cfe824be6017985c1d3b61296e9c83 Mon Sep 17 00:00:00 2001 From: James Panther <4462786+jpanther@users.noreply.github.com> Date: Wed, 19 Jan 2022 12:13:42 +1100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Add=20search=20to=20JS=20a?= =?UTF-8?q?sset=20bundle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/search.js | 4 +--- layouts/partials/head.html | 5 +++++ layouts/partials/search.html | 7 +------ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/assets/js/search.js b/assets/js/search.js index cbc42bdc..89a0b442 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -104,9 +104,7 @@ function fetchJSON(path, callback) { } function buildIndex() { - var baseURL = document - .querySelector('script[data-id="fusejs"][data-url]') - .getAttribute("data-url"); + var baseURL = wrapper.getAttribute("data-url"); fetchJSON(baseURL + "index.json", function (data) { var options = { shouldSort: true, diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 6d1eee96..da96fede 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -56,6 +56,11 @@ {{ $jsDark := resources.Get "js/dark.js" }} {{ $assets.Add "js" (slice $jsDark) }} {{ end }} + {{ if .Site.Params.enableSearch | default false }} + {{ $jsFuse := resources.Get "lib/fuse/fuse.min.js" }} + {{ $jsSearch := resources.Get "js/search.js" }} + {{ $assets.Add "js" (slice $jsFuse $jsSearch) }} + {{ end }} {{ if $assets.Get "js" }} {{ $bundleJS := $assets.Get "js" | resources.Concat "js/main.bundle.js" | resources.Minify | resources.Fingerprint "sha512" }} diff --git a/layouts/partials/search.html b/layouts/partials/search.html index 9a59c49e..0a1eb06d 100644 --- a/layouts/partials/search.html +++ b/layouts/partials/search.html @@ -1,12 +1,7 @@ -{{ $fuseLib := resources.Get "lib/fuse/fuse.min.js" }} -{{ $fuseConfig := resources.Get "js/search.js" }} -{{ $fuseConfig := $fuseConfig | resources.Minify }} -{{ $fuseJS := slice $fuseLib $fuseConfig | resources.Concat "js/fuse.bundle.js" | resources.Fingerprint "sha512" -}} - -