♻️ Add search to JS asset bundle

pull/100/head
James Panther 2022-01-19 12:13:42 +11:00
parent 0842766212
commit dcd5dd0ec9
No known key found for this signature in database
GPG Key ID: D36F789E45745D17
3 changed files with 7 additions and 9 deletions

View File

@ -104,9 +104,7 @@ function fetchJSON(path, callback) {
} }
function buildIndex() { function buildIndex() {
var baseURL = document var baseURL = wrapper.getAttribute("data-url");
.querySelector('script[data-id="fusejs"][data-url]')
.getAttribute("data-url");
fetchJSON(baseURL + "index.json", function (data) { fetchJSON(baseURL + "index.json", function (data) {
var options = { var options = {
shouldSort: true, shouldSort: true,

View File

@ -56,6 +56,11 @@
{{ $jsDark := resources.Get "js/dark.js" }} {{ $jsDark := resources.Get "js/dark.js" }}
{{ $assets.Add "js" (slice $jsDark) }} {{ $assets.Add "js" (slice $jsDark) }}
{{ end }} {{ 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" }} {{ if $assets.Get "js" }}
{{ $bundleJS := $assets.Get "js" | resources.Concat "js/main.bundle.js" | resources.Minify | resources.Fingerprint "sha512" }} {{ $bundleJS := $assets.Get "js" | resources.Concat "js/main.bundle.js" | resources.Minify | resources.Fingerprint "sha512" }}
<script defer type="text/javascript" src="{{ $bundleJS.RelPermalink }}" integrity="{{ $bundleJS.Data.Integrity }}"></script> <script defer type="text/javascript" src="{{ $bundleJS.RelPermalink }}" integrity="{{ $bundleJS.Data.Integrity }}"></script>

View File

@ -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" -}}
<script defer type="text/javascript" src="{{ $fuseJS.RelPermalink }}" integrity="{{ $fuseJS.Data.Integrity }}" data-id="fusejs" data-url="{{ .Site.BaseURL }}"></script>
<div <div
id="search-wrapper" id="search-wrapper"
class="fixed inset-0 z-50 flex flex-col p-4 sm:p-6 md:p-[10vh] lg:p-[12vh] w-screen h-screen cursor-default bg-neutral-500/50 backdrop-blur-sm dark:bg-neutral-900/50 invisible" class="fixed inset-0 z-50 flex flex-col p-4 sm:p-6 md:p-[10vh] lg:p-[12vh] w-screen h-screen cursor-default bg-neutral-500/50 backdrop-blur-sm dark:bg-neutral-900/50 invisible"
data-url="{{ .Site.BaseURL }}"
> >
<div <div
id="search-modal" id="search-modal"