Skip to content

Commit 40cdb0a

Browse files
committed
application.js: allow for relative URLs
When running Hugo with relative URLs, as is the case when a developer runs `hugo` in a regular checkout of this repository, there is no `https://` prefix, and therefore the current logic failed. Fix this logic, and while at it, simplify the preceding code a bit. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 153551c commit 40cdb0a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

assets/js/application.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ popped = 'state' in window.history;
2121
initialURL = location.href;
2222

2323
const baseURLPrefix = (() => {
24-
const scripts = document.getElementsByTagName('script');
25-
const index = scripts.length - 1;
26-
const thisScript = scripts[index];
27-
return thisScript.src.replace(/^.*:\/\/[^/]*(.*\/)(assets|js)\/[^/]+.js(\?.*)?$/, '$1');
24+
const thisScriptSrc =
25+
Array.from(document.getElementsByTagName('script'))
26+
.pop()
27+
.getAttribute('src');
28+
return thisScriptSrc
29+
.replace(/^(?:[a-z]*:\/\/[^/]*)?(.*\/)(assets|js)\/[^/]+.js(\?.*)?$/, '$1');
2830
})();
2931

3032
$(document).ready(function() {

0 commit comments

Comments
 (0)