schnerring / hugo-theme-gruvbox

A retro-looking Hugo theme inspired by gruvbox. The pastel colors are high contrast, easily distinguishable, pleasing to the eye, and feature light and dark color palettes.
MIT License
196 stars 50 forks source link

prism modules aren't loaded correctly when using subdirectory #281

Open Valhrafnaz opened 4 months ago

Valhrafnaz commented 4 months ago

I host my blog at a sub-directory of my overall site, but sadly the theme seems to have misconfigured paths, as adding a subfolder to my baseURL causes the build process to fail thusly:

Error: error building site: POSTCSS: failed to transform "css/non-critical.css" (text/css): CssSyntaxError: postcss-import: /home/valhrafnaz/blog-server/stdin:13:5: Failed to find 'blog/prismjs/plugins/toolbar/prism-toolbar.css'
  in [
    /home/valhrafnaz/blog-server,
    /home/valhrafnaz/.cache/hugo_cache/modules/filecache/modules/pkg/mod/github.com/schnerring/hugo-theme-gruvbox@v0.0.0-20240621140605-37cea91b04c5/assets/css
  ]

  11 |     
  12 |     /* Import stylesheet for Prism plugin 'toolbar' from 'blog/prismjs/plugins/toolbar/prism-toolbar.css' */
> 13 |     @import "blog/prismjs/plugins/toolbar/prism-toolbar.css";
     |     ^
  14 |   
  15 | 

I assume this is caused by using the absolute path rather than the relative path to load the plugins. Removing the /blog from my baseURL causes the build to go without a hitch, but this of course breaks all links since they now missing the sub-directory.

schnerring commented 4 months ago

Have you looked at the hugo -s CLI argument?

-s, --source string              filesystem path to read files relative from

I think you need to run hugo -s blog/

See:

Valhrafnaz commented 4 months ago

Sadly that does not seem to fix the issue whatsoever. Using -s ~/blog/ (the directory which contains the site files) produces the exact same error, which is expected, since that is the directory from which the command is run. The only way avoid this issue seems to be to change the baseURL to an incorrect value as mentioned in the issue. Renaming the build folder to something else (jic there is some weird interaction if the subdir and build folder are named the same) also does not help.

Valhrafnaz commented 4 months ago

I think I have found the fix. Using hugo -v reveals that the resources.postCSS call in layouts/partial/head/stylesheets.html is deprecated. Cloning the repo, replacing said call with the recommended css.postCSS has fixed the issue for me. I don't really have capacity to test this, but on my end this does not seem to produce any other negative side effects.

wesgould commented 3 months ago

I have this same issue. I am guessing it has to do with one of the newer versions of hugo. It works find on my linux machine runninghugo v0.92.2+extended linux/amd64 BuildDate=2023-01-31T11:11:57Z

On my mac running v0.132.1+extended darwin/arm64 I get the error.

I ran a nix flake with v0.132.1+extended on my linux machine and encountered the same issue.

I'll keep digging when I have time, but hopefully that helps someone smarter than me to narrow down what the problem could be.

schnerring commented 3 months ago

Cloning the repo, replacing said call with the recommended css.postCSS has fixed the issue for me.

Thanks for investigating. I bumped the minimum Hugo version to 0.128.0. That's the version where resources.PostCSS was deprecated in favor of css.PostCSS. I changed the code accordingly as per your suggestion.

Maybe you could give it another try since I can't reproduce the issue.