baseURL with subfolder: why is it not working?

Here’s my simple set-up, using the Typo theme:

baseURL = "https://website.com/subfolder"

Sadly, when I then refer to either static resources or to the root folder, in the build it appears as “https://website.com/”, instead of “https://website.com/subfolder”, in things like:

<img loading="lazy" alt="{{ .Text }}" src="{{ $url }}">
<!-- markdown: ![img](/img-in-static.png) => "https://website.com/img-in-static.png
instead of https://website.com/subfolder/img-in-static.png"
!-->

Or

@font-face {
    font-family: 'Literata';
    src: url('/fonts/Literata/Literata-Light.woff2') format('woff2'); /* appears as "https://website.com/fonts... */
                                                                      /*  instead of "https://website.com/subfolder/ fonts... */ */
    font-weight: light;
    font-style: normal;
}

Hugo version:
hugo v0.129.0+extended darwin/arm64 BuildDate=2024-07-17T13:29:16Z VendorInfo=brew

I am browsing various posts reporting the same issues, and yet I am unable to find out what would be the easy way out of this issue? (Is it the browser that looks for the root and therefore removes the subfolder?) It’s a pain as this really is the way e.g. to create multiple sites as various repos on GitHub.

Many thanks in advance for any tips!

Check out this one:

1 Like

Thanks, I had seen this but will now test the solutions from there more calmly!

To properly resolve markdown link and image destinations with v0.123.0 and later you can enable the embedded link and image render hooks:

Remember to mount the static directory to assets as described in the documentation.

2 Likes

Thanks so much for this! I’m sorry for my impulsive post, I was definitely stressed and not taking the time to go through all this in the detail it requires! Great post on the cannonifyURL process mentioned in the above post as well.