Cached resources not found in file cache when baseURL contains subdirectory

I use postcss to make a theme. But for the convenience of users, useResourceCacheWhen = "always" is used in example config, so that user do not need to reley on npm.

But when users set a baseURL with subdomain, such as “https://example.com/test/”, an error will occur like Error building site: POSTCSS: failed to transform "css/eureka.css" (text/css): resource "css/test/css/eureka.css_fingerprint" not found in file cache. Obviously, Hugo uses the subdomain in baseURL as the path to find the cache.

So is there a way that users can use the cache and baseURL subdomains normally without special processing? Because not all users are willing to install the packages required by Hugo pipes. Maybe Hugo need to treat subdomains in baseURL differently?

Sure there is.

Never reference assets in theme templates with a forward slash / in the beginning of the URL.

In a project with a subdomain as the baseURL or a subdirectory the forward slash will always point to the host root and therefore these assets will be 404 when the project is published.

Thank you for your fast reply! But I try to use the following code to reference assets:

{{- $eurekaCSS := resources.Get "css/eureka.css" | postCSS (dict "config" "assets/css/postcss.config.js") }}
{{- $eurekaCSS := $eurekaCSS | minify }}
<link rel="stylesheet" href="{{ $eurekaCSS.Permalink }}">

But I still get the error above.

Try using $eurekaCSS.RelPermalink instead and let me know if that fixes the issue.

This issue still exists with $eurekaCSS.RelPermalink.

The code I used is like:

{{- $eurekaCSS := resources.Get "css/eureka.css" | postCSS (dict "config" "assets/css/postcss.config.js") }}
{{- $eurekaCSS := $eurekaCSS | minify }}
<link rel="stylesheet" href="{{ $eurekaCSS.RelPermalink }}">

And I also observe the output of this line. I use a different baseURL without subdomains and the generated html of that line is /css/eureka.min.css in href

Ok. You need to share a repo for someone to reproduce the issue.

I do not use Post CSS myself, so hopefully someone will have a look.

Thank you for your help!

The repo is on https://github.com/wangchucheng/baseurl-issue.

And the code which references css is in partials/head.html:45.

I tested the repo with the latest Hugo Extended and it appears that something else is going on.

postcss.config.js is not found even if the baseURL is set to a root domain sans subdirectory or subdomain.

Something else is going on, but I cannot look further due to lack of time.

postcss.config.js error is a version problem and I make a commit to fix this. reinstall npm packages should solve it. Sorry about that.

Apart from this, the baseURL problem still exists.