Skip to content

Commit

Permalink
Make hugo.toml the new default config name
Browse files Browse the repository at this point in the history
Note that the old, e.g. config.toml, still works fine.

See gohugoio#8979
  • Loading branch information
bep committed Sep 18, 2021
1 parent 13ad840 commit 8783578
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion commands/new_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func createConfig(fs *hugofs.Fs, inpath string, kind string) (err error) {
return err
}

return helpers.WriteToDisk(filepath.Join(inpath, "config."+kind), &buf, fs.Source)
return helpers.WriteToDisk(filepath.Join(inpath, "hugo."+kind), &buf, fs.Source)
}

func nextStepsText() string {
Expand Down
2 changes: 1 addition & 1 deletion config/configLoader.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func LoadConfigFromDir(sourceFs afero.Fs, configDir, environment string) (Provid

var keyPath []string

if name != "config" {
if name != "hugo" && name != "config" {
// Can be params.jp, menus.en etc.
name, lang := paths.FileAndExtNoDelimiter(name)

Expand Down
2 changes: 1 addition & 1 deletion hugolib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (d ConfigSourceDescriptor) configFileDir() string {

func (d ConfigSourceDescriptor) configFilenames() []string {
if d.Filename == "" {
return []string{"config"}
return []string{"hugo", "config"}
}
return strings.Split(d.Filename, ",")
}
Expand Down
19 changes: 11 additions & 8 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,28 @@ func TestLoadConfig(t *testing.T) {

c := qt.New(t)

loadConfig := func(c *qt.C, configContent string, fromDir bool) config.Provider {
loadConfig := func(c *qt.C, configFilename, configContent string, fromDir bool) config.Provider {
mm := afero.NewMemMapFs()
filename := "config.toml"
descriptor := ConfigSourceDescriptor{Fs: mm}
if fromDir {
filename = filepath.Join("config", "_default", filename)
configFilename = filepath.Join("config", "_default", configFilename)
descriptor.AbsConfigDir = "config"
}
writeToFs(t, mm, filename, configContent)
writeToFs(t, mm, configFilename, configContent)
cfg, _, err := LoadConfig(descriptor)
c.Assert(err, qt.IsNil)
return cfg
}

c.Run("Basic", func(c *qt.C) {
c.Parallel()
// Add a random config variable for testing.
// side = page in Norwegian.
cfg := loadConfig(c, `PaginatePath = "side"`, false)
cfg := loadConfig(c, "hugo.toml", `PaginatePath = "side"`, false)
c.Assert(cfg.GetString("paginatePath"), qt.Equals, "side")
})

c.Run("Basic, old config name", func(c *qt.C) {
c.Parallel()
cfg := loadConfig(c, "config.toml", `PaginatePath = "side"`, false)
c.Assert(cfg.GetString("paginatePath"), qt.Equals, "side")
})

Expand All @@ -64,7 +67,7 @@ func TestLoadConfig(t *testing.T) {
}
c.Run(testName, func(c *qt.C) {
c.Parallel()
cfg := loadConfig(c, `[taxonomies]
cfg := loadConfig(c, "hugo.toml", `[taxonomies]
appellation = "appellations"
vigneron = "vignerons"`, fromDir)

Expand Down

0 comments on commit 8783578

Please sign in to comment.