From 5b724e6023770d24323df1b5ae68119b4f9347f2 Mon Sep 17 00:00:00 2001 From: Robert Mihaly Date: Mon, 7 Mar 2022 13:44:14 +0100 Subject: [PATCH] Set rootURL to the site's baseURL This fixes loading images and other assets in javascripts, when the site is not deployed to the root folder, but into a sub-folder. The fix replaces the server host based `rootURL` with Hugo's `baseURL`. Since this URL is used in calls to `new URL`, it needs to end with a trailing slash for the URLs to be constructed correctly. --- assets/js/variables.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/js/variables.js b/assets/js/variables.js index 3a9636c6..1b5fd882 100644 --- a/assets/js/variables.js +++ b/assets/js/variables.js @@ -4,7 +4,8 @@ const toggleId = 'toggle'; const showId = 'show'; const menu = 'menu'; const active = 'active'; -const rootURL = window.location.protocol + "//" + window.location.host; +// rootURL must end with '/' for relative URLs to work properly +const rootURL = '{{ strings.TrimSuffix "/" .Site.BaseURL }}/'; const searchFieldClass = '.search_field'; const searchClass = '.search'; const goBackClass = 'button_back';