I’d like to reorganize the folders in my Hugo project and I wonder if that is possible, safe, and wise.
Putting /assets
, /content
, /layouts
, and /static
inside a /src
folder would clean things up quite a bit. Renaming /public
to _site
would, too.
I see the publicDir
field is available in the configuration, and I tried that, but it didn’t seem to do anything. Perhaps I have it at the wrong ‘level’ in hugo.toml
? I put at the root and under [params].
How would I go about customizing the location of the other folders?
Ah! Mounts! I’ll do some work with that. Thanks.
1 Like
[module]
[[module.mounts]]
source = 'source/content'
target = 'content'
[[module.mounts]]
source = 'source/layouts'
target = 'layouts'
[[module.mounts]]
source = 'source/assets'
target = 'assets'
ERROR POSTCSS: failed to transform "/css/lightbox.css" (text/css): postcss config "./assets/css/postcss.config.mjs" not found
Built in 95 ms
Change the location of content
and layouts
works, but assets
throws an error.
I must be missing something.
Where is the site configuration file or directory located? Within the source
directory or somewhere else?
From which directory are you issuing the hugo
command?
What is the complete command line string?
Assuming the site config is in the project root, and that you are issuing the command from the project root, this setup works great:
git clone --single-branch -b hugo-forum-topic-54272 https://github.com/jmooring/hugo-testing hugo-forum-topic-54272
cd hugo-forum-topic-54272
npm ci
rm -rf resources/ _site/ && hugo && cat _site/css/main.css
hugo.toml
is in the project root and the command rm -rf public && rm -rf resources && hugo server
was issued from the root of the project, as well.
Are those CLI commands intended to be issued in a fresh directory or into the project directory?
It is a test site. Issue them from a temporary and clean directory.
That works fine. I need to dig deeper…
Trouble was coming from
{{- $styles := resources.Get "css/styles.css" | postCSS (dict "config" "./assets/css/postcss.config.mjs") -}}
{{- if hugo.IsServer }}
{{ $styles = $styles | resources.ExecuteAsTemplate (printf "css/styles.dev.%v.css" now.UnixMilli) .}}
{{ else }}
{{ $styles = $styles | minify | fingerprint | resources.PostProcess }}
{{ end -}}
{{- $lightbox := resources.Get "css/lightbox.css" | postCSS (dict "config" "./assets/css/postcss.config.mjs") -}}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}">
<link rel="stylesheet" href="{{ $lightbox.RelPermalink }}">
where the call to ./assets/css/postcss.config.mjs
was failing.
Changing to ./source/assets/css/postcss.config.mjs
fixed it.
But Hugo keeps generating to public
!
baseURL = 'https://bobrockefeller.com/'
languageCode = 'en-us'
title = 'Bob Rockefeller'
[Params]
description = 'What is Bob up to now?'
customCSS = ["/css/lightbox.css", "/css/custom.css"] # Include custom CSS files
customJS = ["/js/lightbox.js"] # Include custom JS files
# Configure Pagination. See https://gohugo.io/templates/pagination/#configuration
[pagination]
pagerSize = 4
[markup]
[markup.goldmark]
[markup.goldmark.parser]
[markup.goldmark.parser.attribute]
block = true
title = true
[markup.goldmark.renderHooks]
[markup.goldmark.renderHooks.image]
enableDefault = false
[markup.goldmark.renderHooks.link]
enableDefault = true
[markup.goldmark.renderer]
unsafe = true # true allows HTML in md files
[menu]
[[menu.main]]
name = "Home"
url = "/"
weight = 1
[[menu.main]]
name = "About"
url = "/about"
weight = 2
[[menu.main]]
name = "Categories"
url = "/categories"
weight = 3
[[menu.main]]
name = "Tags"
url = "/tags"
weight = 4
[taxonomies]
tag = "tags"
category = "categories"
publishDir = '_site'
[module]
[[module.mounts]]
source = 'source/content'
target = 'content'
[[module.mounts]]
source = 'source/layouts'
target = 'layouts'
[[module.mounts]]
source = 'source/assets'
target = 'assets'
[[module.mounts]]
source = 'source/static'
target = 'static'
You have placed the publish directory key under another table. It should be in the root.
Of course! I forgot about .toml
vs. yaml
.
Now… Is it possible to rename resources
to _resources
?
Search the docs for resourceDir.