chipzoller / hugo-clarity

A theme for Hugo based on VMware Clarity
Other
571 stars 263 forks source link

Site URLs in subdirs break various things #322

Closed rootwork closed 2 years ago

rootwork commented 2 years ago

I have checked all the prerequisites below and I'm yet experiencing a problem

Describe the bug

I was trying to debug an issue where the link.svg images in hovered sub-heading permalinks were not showing up for me in situations where the site was in a subdirectory (e.g. a GitHub Pages site like username.github.io/projectname).

When I looked at how the path to that file is constructed, it's ${parentURL}${iconsPath}link.svg. I know iconsPath is fine because my "light switch" mode icons show up fine. So then I looked up parentURL:

// variables read from your hugo configuration
const parentURL = window.location.protocol + "//" + window.location.host + "/";

The comment implies that this is being read from Hugo config, but it's not -- it's constructed just looking at what's in the browser window, and it only reads the domain name, not subdir(s). Shouldn't this just use Hugo's own .Site.BaseURL value?

I can make a PR for this, but I wasn't sure how else parentURL might be getting used, or what assumptions there are about it.

rootwork commented 2 years ago

Assigning @onweru as I'm guessing this is your area.

rootwork commented 2 years ago

Update: This happens with rootURL used in the search feature as well, which is basically defined the same way (except no trailing slash). The search scripts can't access index.json, because it looks for it in <rootdomain>/index.json instead of <baseURL-including-subdir>/index.json.

I think both of these should be adapted to use .SiteBaseURL to allow for installs in subdirectories.

rootwork commented 2 years ago

I now have a PR for this in #324, so requesting @onweru's review there instead.