How to change the project root folder to a subdirectory?


I’ve recently migrated from Middleman to Hugo and I love it.

I am trying to clean up my project directory structure a bit. I eventually achieved the structure I want, but I am sure there is an easier way to do the same without so many changes to the config.toml.

I want to move my site source code to a subdirectory like “src” so that I keep all the generated stuff, deploy scripts, and dependencies out of it.

This is the final structure:


I’ve achieved that by changing each and every folder inside my config.toml like this:

archetypeDir = "src/archetypes"
assetDir = "src/assets"
contentDir = "src/content"
dataDir = "src/data"
layoutDir = "src/layouts"
staticDir = "src/static"
themesDir = "src/themes"

As you can see, these are 7 config settings to change the project root folder. Is there a way to achieve the same with simpler and DRYed config.toml? Couldn’t find it in the docs.


The only way is using -s flag in hugo command.

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

I saw that command-line option in the docs, but the problem with it is that it creates the “public” and “resources” folders inside the source folder “src”. That is something, I want to avoid. I guess I will keep my current configuration file as it is.


In combination with configuration parameters publishDir and resourceDir the command line option should still work. The config needs to be relative to the src directory, but you can change out of there easily with ../ - you can even fine-tune how resources and cached files are sorted:

The implementation in Victor-hugo is probably a good reference point, as all Hugo things have been moved into /site while keeping the generic assets in /src with the Hugo build command redefines both input and output directories for Hugo, building out to a generic /dist directory rather than /public.