I’ve just started using Hugo, created a new site and a theme.
Why do css files need to be placed in themes/mytheme/assets folder, not themes/mytheme/static?
I’ve edited themes/mytheme/layouts/partials/head/css.html like you can see below. But Hugo seems to only be looking css up in themes/mytheme/assets.
{{- with resources.Get “css/normalize.css” }}{{- if eq hugo.Environment “development” }}
{{- else }}{{- with . | minify | fingerprint }}
{{- end }}{{- end }}{{- end }}
{{- with resources.Get “css/bettertext.css” }}{{- if eq hugo.Environment “development” }}
{{- else }}{{- with . | minify | fingerprint }}
{{- end }}{{- end }}{{- end }}
The static directory contains files that will be copied to the public directory when you build your site. For example: favicon.ico, robots.txt, and files that verify site ownership. Before the introduction of page bundles and asset pipelines, the static directory was also used for images, CSS, and JavaScript.
As for refreshing public, this command $ hugo server -w --cleanDestinationDir did nothing. I. e. after I moved themes/mytheme/static/css/normalize.css etc. to themes/mytheme/assets/css/, the site look was not updated, also not in another browser. I removed public contents manually, after which the site look did refresh.
That is not true. It clears the public directory when a static directory exists as shown in my previous comment. And the -w flag is superfluous; it can be removed.
When running hugo server there are several known issues related to automatic page refresh. Whether you are running into a known issue is impossible to know without more information (i.e., access to your project repository).
Like I said, I am new to Hugo and may have very well done something wrong.
But this is the dir with the project. All I’ve done was – create a new site and a theme. Next, I tried to add my own css and remove the default one. I very much appreciate your help.
I use stock Fedora Linux. Hugo version: hugo v0.142.0+extended linux/amd64 BuildDate=2025-01-24T00:00:00+00:00 VendorInfo=Fedora:0.142.0-4.fc42.
your css problem is solved - at least your provided repo loads your custom stuff. I consider that as soved and closed.
If your last post is another question, please open a new issue.
hints:
common usage for a theme is to provide layout and styling, so I would move the content folder to the root of your repo to separate “UI” and content
If you start from scratch, I would use an up to date hugo v0.145.0 - last one using the old widely spread template organization (with many web resources)
for cutting edge and the new template system use the latest (currently v0.148.2).