diff --git a/layouts/partials/head/scripts.html b/layouts/partials/head/scripts.html
index e2dea4f..6b9c326 100644
--- a/layouts/partials/head/scripts.html
+++ b/layouts/partials/head/scripts.html
@@ -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) {