diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-01-15 18:45:51 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-01-16 15:34:16 +0100 |
commit | f38a2fbd2e4de7f095a833b448cb8bc053955ce2 (patch) | |
tree | 3c88d0c12efa09ef3cc189a5859620b771004c7f /hugolib/config.go | |
parent | 6a579ebac3a81df61f22988e3eb55f7cb35ce523 (diff) | |
download | hugo-f38a2fbd2e4de7f095a833b448cb8bc053955ce2.tar.gz hugo-f38a2fbd2e4de7f095a833b448cb8bc053955ce2.zip |
Make hugo.toml the new config.toml
Both will of course work, but hugo.toml will win if both are set.
We should have done this a long time ago, of course, but the reason I'm picking this up now is that my VS Code setup by default picks up some
JSON config schema from some random other software which also names its config files config.toml.
Fixes #8979
Diffstat (limited to 'hugolib/config.go')
-rw-r--r-- | hugolib/config.go | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/hugolib/config.go b/hugolib/config.go index 8e73a35ec..059424e85 100644 --- a/hugolib/config.go +++ b/hugolib/config.go @@ -69,18 +69,35 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid // use a partial configuration to do its job. defer l.deleteMergeStrategies() - for _, name := range d.configFilenames() { - var filename string - filename, err := l.loadConfig(name) - if err == nil { - configFiles = append(configFiles, filename) - } else if err != ErrNoConfigFile { - return nil, nil, l.wrapFileError(err, filename) + names := d.configFilenames() + + if names != nil { + for _, name := range names { + var filename string + filename, err := l.loadConfig(name) + if err == nil { + configFiles = append(configFiles, filename) + } else if err != ErrNoConfigFile { + return nil, nil, l.wrapFileError(err, filename) + } + } + } else { + for _, name := range config.DefaultConfigNames { + var filename string + filename, err := l.loadConfig(name) + if err == nil { + configFiles = append(configFiles, filename) + break + } else if err != ErrNoConfigFile { + return nil, nil, l.wrapFileError(err, filename) + } } } if d.AbsConfigDir != "" { + dcfg, dirnames, err := config.LoadConfigFromDir(l.Fs, d.AbsConfigDir, l.Environment) + if err == nil { if len(dirnames) > 0 { l.cfg.Set("", dcfg.Get("")) @@ -162,9 +179,9 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid return l.cfg, configFiles, err } -// LoadConfigDefault is a convenience method to load the default "config.toml" config. +// LoadConfigDefault is a convenience method to load the default "hugo.toml" config. func LoadConfigDefault(fs afero.Fs) (config.Provider, error) { - v, _, err := LoadConfig(ConfigSourceDescriptor{Fs: fs, Filename: "config.toml"}) + v, _, err := LoadConfig(ConfigSourceDescriptor{Fs: fs}) return v, err } @@ -202,7 +219,7 @@ func (d ConfigSourceDescriptor) configFileDir() string { func (d ConfigSourceDescriptor) configFilenames() []string { if d.Filename == "" { - return []string{"config"} + return nil } return strings.Split(d.Filename, ",") } |