search index rollback

This commit is contained in:
zzossig 2020-02-06 03:52:41 +09:00
parent 5f7b9aafb4
commit 425cbb5781
1 changed files with 43 additions and 8 deletions

View File

@ -78,9 +78,6 @@
}
// ===============================================================
{{ $permalink := .Permalink }}
var permalink = JSON.parse({{ $permalink | jsonify }});
document.addEventListener('DOMContentLoaded', function () {
// ============================ tab ============================
document.querySelectorAll('.tab') ?
@ -554,6 +551,44 @@
// ========================== search ==========================
var baseurl = null;
{{ $siteBaseURL:= .Site.BaseURL }}
var siteBaseURL = JSON.parse({{ $siteBaseURL | jsonify }});
var siteBaseChecker = /\/\w+\//i;
var isSlug = siteBaseChecker.test(siteBaseURL);
var isThemeSite = location.origin.includes('themes.gohugo.io');
{{ if .Site.IsMultiLingual }}
if (isThemeSite) {
baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
} else {
var hasLangPostfix = location.pathname.includes("/{{.Site.Language.Lang}}");
if (hasLangPostfix) {
if (isSlug) {
baseurl = location.origin + siteBaseURL.match(siteBaseChecker)[0] + "{{.Site.Language.Lang}}";
} else {
baseurl = location.origin + "/{{.Site.Language.Lang}}";
}
} else {
if (isSlug) {
baseurl = location.origin + siteBaseURL.match(siteBaseChecker)[0];
} else {
baseurl = location.origin;
}
}
}
{{ else }}
if (isThemeSite) {
baseurl = "{{.Site.BaseURL}}";
} else {
if (isSlug) {
baseurl = location.origin + siteBaseURL.match(siteBaseChecker)[0];
} else {
baseurl = location.origin;
}
}
{{ end }}
var searchResults = null;
var searchMenu = null;
var searchText = null;
@ -563,13 +598,13 @@
var fuse = null;
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function initFuse() {
if (!endsWith(baseurl, "/")) {
baseurl = baseurl + '/';
};
var xhr = new XMLHttpRequest();
xhr.open('GET', permalink + "index.json");
xhr.open('GET', baseurl + "index.json");
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.onload = function () {
if (xhr.status === 200) {