mirror of
https://github.com/Wonderfall/hugo-WonderMod.git
synced 2024-11-22 02:21: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 fuse; // holds our search engine
|
||||||
var resList = document.getElementById('searchResults');
|
var resList = document.getElementById('searchResults');
|
||||||
var sInput = document.getElementById('searchInput');
|
var sInput = document.getElementById('searchInput');
|
||||||
var first, last = null
|
var first, last = null
|
||||||
var resultsAvailable = false;
|
var resultsAvailable = false;
|
||||||
|
|
||||||
// load our search index, only executed onload
|
// load our search index
|
||||||
function loadSearch() {
|
window.onload = function () {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === 4) {
|
||||||
@ -24,7 +26,7 @@ function loadSearch() {
|
|||||||
'content'
|
'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
|
fuse = new Fuse(data, options); // build the index from the json file
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,14 +61,14 @@
|
|||||||
{{- /* Search */}}
|
{{- /* Search */}}
|
||||||
{{- if (eq .Layout `search`) -}}
|
{{- if (eq .Layout `search`) -}}
|
||||||
<link crossorigin="anonymous" rel="preload" as="fetch" href="../index.json">
|
<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" }}
|
{{- $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 }}
|
||||||
<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 }}
|
{{- else }}
|
||||||
{{- $search := (slice $fusejs $fastsearch ) | resources.Concat "assets/js/search.js" | minify }}
|
{{- $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 }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user