From c3d6d757607fc9a1e451206d60ff2a8b44009d6c Mon Sep 17 00:00:00 2001 From: Reorx Date: Wed, 13 Apr 2022 00:30:45 +0800 Subject: [PATCH] makes search plays well with InstantClick by moving search script into footer.html and stop loading InstantClick when page is search --- layouts/partials/footer.html | 16 ++++++++++++++++ layouts/partials/head.html | 14 -------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 52e80fe..8f5cca8 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -211,8 +211,22 @@ } })(); + +{{- /* Search */}} +{{- if (eq .Layout `search`) -}} + +{{- $fastsearch := resources.Get "js/fastsearch.js" | js.Build (dict "params" (dict "fuseOpts" site.Params.fuseOpts)) }} +{{- $fusejs := resources.Get "js/fuse.basic.min.js" }} +{{- if not site.Params.assets.disableFingerprinting }} +{{- $search := (slice $fusejs $fastsearch ) | resources.Concat "assets/js/search.js" | minify | fingerprint }} + +{{- else }} +{{- $search := (slice $fusejs $fastsearch ) | resources.Concat "assets/js/search.js" | minify }} + {{- end }} +{{- else }} + {{- /* InstantClick.js */}} {{- if (.Param "EnableInstantClick") }} {{- $instantclick := slice (resources.Get "js/instantclick.js") | resources.Concat "assets/js/instantclick.js" | minify }} @@ -221,3 +235,5 @@ > {{- end }} + +{{- end -}} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 99d33ae..a5dac53 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -58,20 +58,6 @@ {{- end }} -{{- /* Search */}} -{{- if (eq .Layout `search`) -}} - -{{- $fastsearch := resources.Get "js/fastsearch.js" | js.Build (dict "params" (dict "fuseOpts" site.Params.fuseOpts)) }} -{{- $fusejs := resources.Get "js/fuse.basic.min.js" }} -{{- if not site.Params.assets.disableFingerprinting }} -{{- $search := (slice $fusejs $fastsearch ) | resources.Concat "assets/js/search.js" | minify | fingerprint }} - -{{- else }} -{{- $search := (slice $fusejs $fastsearch ) | resources.Concat "assets/js/search.js" | minify }} - -{{- end }} -{{- end -}} - {{- /* Highlight.js */}} {{- $isHLJSdisabled := (site.Params.assets.disableHLJS | default .Params.disableHLJS ) }} {{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (not $isHLJSdisabled)) }}