search index rollback
This commit is contained in:
parent
5f7b9aafb4
commit
425cbb5781
|
@ -78,9 +78,6 @@
|
||||||
}
|
}
|
||||||
// ===============================================================
|
// ===============================================================
|
||||||
|
|
||||||
{{ $permalink := .Permalink }}
|
|
||||||
var permalink = JSON.parse({{ $permalink | jsonify }});
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
// ============================ tab ============================
|
// ============================ tab ============================
|
||||||
document.querySelectorAll('.tab') ?
|
document.querySelectorAll('.tab') ?
|
||||||
|
@ -554,6 +551,44 @@
|
||||||
|
|
||||||
|
|
||||||
// ========================== search ==========================
|
// ========================== 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 searchResults = null;
|
||||||
var searchMenu = null;
|
var searchMenu = null;
|
||||||
var searchText = null;
|
var searchText = null;
|
||||||
|
@ -563,13 +598,13 @@
|
||||||
|
|
||||||
var fuse = null;
|
var fuse = null;
|
||||||
|
|
||||||
function endsWith(str, suffix) {
|
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function initFuse() {
|
function initFuse() {
|
||||||
|
if (!endsWith(baseurl, "/")) {
|
||||||
|
baseurl = baseurl + '/';
|
||||||
|
};
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
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.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
|
|
Loading…
Reference in New Issue