From 7dff0a3f08793ee1265cace4263f4ce4f102c257 Mon Sep 17 00:00:00 2001 From: zzossig Date: Thu, 11 Jun 2020 14:02:09 +0900 Subject: [PATCH] [bug fix] Don't initialize search when disabled fix #253 --- layouts/partials/head/scripts.html | 52 ++++++++++++++++-------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/layouts/partials/head/scripts.html b/layouts/partials/head/scripts.html index 42751e4..0006285 100644 --- a/layouts/partials/head/scripts.html +++ b/layouts/partials/head/scripts.html @@ -558,6 +558,8 @@ var searchMenu = null; var searchText = null; + {{ $enableSearch := ($.Param "enableSearch") }} + var enableSearch = JSON.parse({{ $enableSearch | jsonify }}); {{ $enableSearchHighlight := ($.Param "enableSearchHighlight") }} var enableSearchHighlight = JSON.parse({{ $enableSearchHighlight | jsonify }}); {{ $searchResultPosition := ($.Param "searchResultPosition") }} @@ -567,30 +569,32 @@ var fuse = null; - (function initFuse() { - var xhr = new XMLHttpRequest(); - xhr.open('GET', baseurl + "/index.json"); - xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); - xhr.onload = function () { - if (xhr.status === 200) { - fuse = new Fuse(JSON.parse(xhr.response.toString('utf-8')), { - keys: sectionType.includes('publication') ? ['title', 'abstract'] : ['title', 'description', 'content'], - includeMatches: enableSearchHighlight, - shouldSort: true, - threshold: 0.4, - location: 0, - distance: 100, - maxPatternLength: 32, - minMatchCharLength: 1, - }); - window.fuse = fuse; - } - else { - console.error('[' + xhr.status + ']Error:', xhr.statusText); - } - }; - xhr.send(); - })(); + if (enableSearch) { + (function initFuse() { + var xhr = new XMLHttpRequest(); + xhr.open('GET', baseurl + "/index.json"); + xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); + xhr.onload = function () { + if (xhr.status === 200) { + fuse = new Fuse(JSON.parse(xhr.response.toString('utf-8')), { + keys: sectionType.includes('publication') ? ['title', 'abstract'] : ['title', 'description', 'content'], + includeMatches: enableSearchHighlight, + shouldSort: true, + threshold: 0.4, + location: 0, + distance: 100, + maxPatternLength: 32, + minMatchCharLength: 1, + }); + window.fuse = fuse; + } + else { + console.error('[' + xhr.status + ']Error:', xhr.statusText); + } + }; + xhr.send(); + })(); + } function makeLi(ulElem, obj) { var li = document.createElement('li');