I recently realized it was possible to merge several config files using the --config
flag of the Hugo command. with hugo serve --config a.toml, b.toml
thanks to this commit.
The most common use case for this is to define several layers of configuration depending on your environement.
Users will have a base file stating all the shared config properties and then use another config files with the few properties unique to an environement to be merged on top of it like so
#config.base.toml
DefaultContentLanguage = "en"
MetaDataFormat = "yaml"
title = « My Website »
theme = "onefinetheme"
[...]
#config.base.toml
[params]
env = "local"
contactFormApi = "https://api.mail.loc"
# config.prod.toml
[params]
env = "production"
contactFormApi = "https://api.mail.com"
disqusShortname = "commentswelcome"
$ hugo --config base.config.toml,prod.config.toml
This is the proper way to manage several environments config files sharing many common properties I think.
But as this is a major feature and for a very common use case, I don’t think this capability should be left isolated to a mere cli command flag but rather made into a dedicated configuration feature which does not rely on cli.
This would allow a proper documentation of the feature and advertising of the proper way of sharing common configuration on several environements.
In this sense why not add a configuration property called something like “extends” which will let Hugo know a configuration file uses (and overwrites) the properties of another one like so:
# config.local.toml
expand = "config.base.toml"
[params]
env = "local"
contactFormApi = "https://api.mail.loc"
# config.production.toml
expand = "config.base.toml"
[params]
env = "production"
contactFormApi = "https://api.mail.com"
disqusShortname = "commentswelcome"
Cheers