I have some custom CSS for my home page (and a couple of others). I’ve named my file .scss, in this case home.scss. My head.html searches for and imports this, this part is working fine for all pages.
I want to split it up a bit to keep it tidy, so I’ve created _banner.scss.
I’m a little confused, from what I’ve read about page bundles, any additional files should be page resources? My home.scss file appears to be in the current directory but the _banner.scss does not.
So, from what you’ve said, am I correct in thinking the build process goes:
Hugo builds _index.html. Presume that Hugo does this in some temporary directory.
Hugo sees home.scss and pulls this into the page bundle. Hugo knows where to find this file.
Hugo calls Dart to compile the scss.
Dart tries to build home.scss from the temporary directory.
Dart finds the @use ‘banner’ line but, does not know where to find this file?
If this is correct, is there a way for Hugo to tell Dart where the ‘current directory’ is using the --load-path parameter?
Understood, so I have css.html in my layout, which is (nearly) the default one created with the hugo new theme command. I’ve modified it slightly to include the .Title scss file.
{{- $styles := slice (resources.Get "css/styles.scss") }}
{{- with .Resources.Get (printf "%s.scss" .Title) }}
{{- $styles = $styles | append . }}
{{- end }}
{{- range $styles }}
{{- $css := . | toCSS (dict "transpiler" "dartsass") }}
{{- if eq hugo.Environment "development" }}
<link rel="stylesheet" href="{{ $css.RelPermalink }}">
{{- else }}
{{- with $css | minify | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{- end }}
{{- end }}
{{- end }}
So something would have to happen here, to look for all scss files? Anything beginning with an _ would be processed by Dart, so it only needs to be available at that time?
Seems like this may be an overcomplicated solution to a minor aethetic issue.
git clone --single-branch -b hugo-forum-topic-55035 https://github.com/jmooring/hugo-testing hugo-forum-topic-55035
cd hugo-forum-topic-55035
hugo server
Files of interest:
layouts/baseof.html (line 7)
layouts/_partials/page-css.html
content/posts/post-1/sass/* (the page resources)
In my view this isn’t a great idea because:
It’s complicated
Your published site will include the Sass files. You can disable the publishing of page resources using build options, but that is coarse-grained (i.e., you can’t disable publishing based on media type, extension, path, etc.):
Thanks @jmooring for spending the time on that example.
Agree it’s not great to have the Sass in the build. I think this may be a case of it being more complicated than it’s worth for this issue. Maybe something to build into a future version of Hugo somehow.
One other thought, @bep suggested using includePaths, could this be used to automatically include the relevant directory inside content? I’m not sure if you can do this in front matter or something like that?