diff options
author | Ivan Boothe <git@rootwork.org> | 2022-06-10 23:47:53 +0300 |
---|---|---|
committer | Ivan Boothe <git@rootwork.org> | 2022-06-10 23:47:53 +0300 |
commit | 2b6a09378d5b966abe243be1c63a3f503a47ce98 (patch) | |
tree | 0df3c2899ecfda7c4c53d97a650fe47425f2fe28 | |
parent | c36221fc715d0b6cd25e4008ca94ee33bfff5a19 (diff) |
Replacing parentURL and rootURL with baseURL derived from Hugo config
Signed-off-by: Ivan Boothe <git@rootwork.org>
-rw-r--r-- | assets/js/code.js | 4 | ||||
-rw-r--r-- | assets/js/functions.js | 3 | ||||
-rw-r--r-- | assets/js/index.js | 4 | ||||
-rw-r--r-- | assets/js/search.js | 4 | ||||
-rw-r--r-- | assets/js/variables.js | 2 |
5 files changed, 8 insertions, 9 deletions
diff --git a/assets/js/code.js b/assets/js/code.js index 6746065..bdaff51 100644 --- a/assets/js/code.js +++ b/assets/js/code.js @@ -139,7 +139,7 @@ function actionPanel() { btn.className = `icon panel_icon panel_${button.id}`; button.show ? false : pushClass(btn, panelHide); // load icon inside button - btn.style.backgroundImage = `url(${parentURL}${iconsPath}${button.icon}.svg)`; + btn.style.backgroundImage = `url(${baseURL}${iconsPath}${button.icon}.svg)`; // append button on panel panel.appendChild(btn); }); @@ -274,4 +274,4 @@ function disableCodeLineNumbers(block){ } }); })(); -})();
\ No newline at end of file +})(); diff --git a/assets/js/functions.js b/assets/js/functions.js index 12187df..e40076f 100644 --- a/assets/js/functions.js +++ b/assets/js/functions.js @@ -2,7 +2,6 @@ const doc = document.documentElement; const inline = ":inline"; // variables read from your hugo configuration -const parentURL = window.location.protocol + "//" + window.location.host + "/"; let showImagePosition = "{{ .Site.Params.figurePositionShow }}"; const showImagePositionLabel = '{{ .Site.Params.figurePositionLabel }}'; @@ -269,4 +268,4 @@ function goBack(target) { if(platform.includes("win")) { pushClass(bodyElement, 'windows'); } -})();
\ No newline at end of file +})(); diff --git a/assets/js/index.js b/assets/js/index.js index 6c33ac8..cf8e74c 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -73,7 +73,7 @@ function fileClosure(){ Array.from(links).forEach(function(link){ let target, rel, blank, noopener, attr1, attr2, url, isExternal; url = elemAttribute(link, 'href'); - isExternal = (url && typeof url == 'string' && url.startsWith('http')) && !url.startsWith(parentURL) ? true : false; + isExternal = (url && typeof url == 'string' && url.startsWith('http')) && !url.startsWith(baseURL) ? true : false; if(isExternal) { target = 'target'; rel = 'rel'; @@ -105,7 +105,7 @@ function fileClosure(){ headingNodes.forEach(function(node){ link = createEl('a'); link.className = 'link icon'; - link.style.backgroundImage = `url(${parentURL}${iconsPath}link.svg)`; + link.style.backgroundImage = `url(${baseURL}${iconsPath}link.svg)`; id = node.getAttribute('id'); if(id) { link.href = `${current}#${id}`; diff --git a/assets/js/search.js b/assets/js/search.js index 9dde9b0..2352a88 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -124,7 +124,7 @@ function initializeSearch(index) { const searchTerm = searchField.value.trim().toLowerCase(); if(searchTerm.length) { const scopeParameter = searchScope ? `&scope=${searchScope}` : ''; - window.location.href = new URL(`search/?query=${searchTerm}${ scopeParameter }`, rootURL).href; + window.location.href = new URL(`search/?query=${searchTerm}${ scopeParameter }`, baseURL).href; } }); } @@ -211,7 +211,7 @@ function initializeSearch(index) { window.addEventListener('load', function() { const pageLanguage = document.documentElement.lang; const searchIndex = `${ pageLanguage === 'en' ? '': pageLanguage}/index.json`; - fetch(new URL(searchIndex, rootURL).href) + fetch(new URL(searchIndex, baseURL).href) .then(response => response.json()) .then(function(data) { data = data.length ? data : []; diff --git a/assets/js/variables.js b/assets/js/variables.js index ed949e3..93dc40a 100644 --- a/assets/js/variables.js +++ b/assets/js/variables.js @@ -4,7 +4,7 @@ const scaleImageClass = 'image-scale'; const pageHasLoaded = 'DOMContentLoaded'; const imageAltClass = 'img_alt' -const rootURL = window.location.protocol + "//" + window.location.host; +const baseURL = '{{ .Site.BaseURL }}'; const searchFieldClass = '.search_field'; const searchClass = '.search'; const goBackClass = 'button_back'; |