mirror of
https://github.com/Wonderfall/hugo-WonderMod.git
synced 2024-11-21 18:11:37 +01:00
Use js.Build to fetch fuseOpts;
also load Search on window load
This commit is contained in:
parent
b756217126
commit
ba48765e2c
@ -1,11 +1,13 @@
|
||||
import * as params from '@params';
|
||||
|
||||
var fuse; // holds our search engine
|
||||
var resList = document.getElementById('searchResults');
|
||||
var sInput = document.getElementById('searchInput');
|
||||
var first, last = null
|
||||
var resultsAvailable = false;
|
||||
|
||||
// load our search index, only executed onload
|
||||
function loadSearch() {
|
||||
// load our search index
|
||||
window.onload = function () {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
@ -24,7 +26,7 @@ function loadSearch() {
|
||||
'content'
|
||||
]
|
||||
};
|
||||
{{ if . }}options = {{ jsonify . }}{{ end }} // load custom options from .Site.Params.fuseOpts
|
||||
if (params.fuseOpts) options = params.fuseOpts;
|
||||
fuse = new Fuse(data, options); // build the index from the json file
|
||||
}
|
||||
} else {
|
||||
|
@ -61,14 +61,14 @@
|
||||
{{- /* Search */}}
|
||||
{{- if (eq .Layout `search`) -}}
|
||||
<link crossorigin="anonymous" rel="preload" as="fetch" href="../index.json">
|
||||
{{- $fastsearch := resources.Get "js/fastsearch.js" | resources.ExecuteAsTemplate "js/fastsearch.js" .Site.Params.fuseOpts }}
|
||||
{{- $fastsearch := resources.Get "js/fastsearch.js" | js.Build (dict "params" (dict "fuseOpts" .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 }}
|
||||
<script defer crossorigin="anonymous" src="{{ $search.RelPermalink }}" onload="loadSearch();" integrity="{{ $search.Data.Integrity }}"></script>
|
||||
<script defer crossorigin="anonymous" src="{{ $search.RelPermalink }}" integrity="{{ $search.Data.Integrity }}"></script>
|
||||
{{- else }}
|
||||
{{- $search := (slice $fusejs $fastsearch ) | resources.Concat "assets/js/search.js" | minify }}
|
||||
<script defer crossorigin="anonymous" src="{{ $search.RelPermalink }}" onload="loadSearch();"></script>
|
||||
<script defer crossorigin="anonymous" src="{{ $search.RelPermalink }}"></script>
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user