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 19, 2021
1 parent 13ad840 commit a48672f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestExecute(t *testing.T) {
siteDir := filepath.Join(dir, "mysite")
resp := Execute([]string{"new", "site", siteDir, "-e=staging"})
c.Assert(resp.Err, qt.IsNil)
config := readFileFrom(c, filepath.Join(siteDir, "config.toml"))
config := readFileFrom(c, filepath.Join(siteDir, "hugo.toml"))
c.Assert(config, qt.Contains, "baseURL = 'http://example.org/'")
checkNewSiteInited(c, siteDir)
})
Expand All @@ -133,7 +133,7 @@ func checkNewSiteInited(c *qt.C, basepath string) {
filepath.Join(basepath, "archetypes"),
filepath.Join(basepath, "static"),
filepath.Join(basepath, "data"),
filepath.Join(basepath, "config.toml"),
filepath.Join(basepath, "hugo.toml"),
}

for _, path := range paths {
Expand Down
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 a48672f

Please sign in to comment.