Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zzossig/hugo-theme-zdoc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzzossig <zzossig@gmail.com>2020-02-05 22:11:30 +0300
committerzzossig <zzossig@gmail.com>2020-02-05 22:11:30 +0300
commitb9b1be1a78e88104ae151a965c0b553cb1f4366f (patch)
treed6ca2d0f2c08e9bc082e53dfd9730dbe78b21dff
parent5417240e3a8e27ccc5e81e40529357cec38a718b (diff)
Update scripts.html
-rw-r--r--layouts/partials/head/scripts.html52
1 files changed, 48 insertions, 4 deletions
diff --git a/layouts/partials/head/scripts.html b/layouts/partials/head/scripts.html
index a41ece9..8820062 100644
--- a/layouts/partials/head/scripts.html
+++ b/layouts/partials/head/scripts.html
@@ -12,9 +12,6 @@
<script>
"use strict";
- {{ $permalink := .Permalink }}
- var permalink = JSON.parse({{ $permalink | jsonify }});
-
window.onload = function() {
// ========================== expand ==========================
var expandBtn = document.querySelectorAll('.expand__button');
@@ -303,6 +300,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;
@@ -311,9 +346,18 @@
var enableSearchHighlight = JSON.parse({{ $enableSearchHighlight | jsonify }});
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) {