Skip to content

Commit

Permalink
Set rootURL to the site's baseURL
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mihalyr authored and onweru committed Dec 30, 2022
1 parent 0a15e2b commit 5b724e6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion assets/js/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 5b724e6

Please sign in to comment.