hugolib: Only set 'allThemes' if there are themes in the config file

When the 'allThemes' configuration setting is read, it will panic if
there are no themes. This was a regression introduced in Hugo 0.42.

Also updated a unit test to check for this.

Fixes #4851
This commit is contained in:
Garry McNulty 2018-07-15 14:35:41 +01:00 committed by Bjørn Erik Pedersen
parent 2f2bc7ff70
commit 38204c4ab6
2 changed files with 7 additions and 0 deletions

View file

@ -285,6 +285,11 @@ func loadThemeConfig(d ConfigSourceDescriptor, v1 *viper.Viper) ([]string, error
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(themeConfigs) == 0 {
return nil, nil
}
v1.Set("allThemes", themeConfigs) v1.Set("allThemes", themeConfigs)
var configFilenames []string var configFilenames []string

View file

@ -42,6 +42,8 @@ func TestLoadConfig(t *testing.T) {
assert.Equal("side", cfg.GetString("paginatePath")) assert.Equal("side", cfg.GetString("paginatePath"))
// default // default
assert.Equal("layouts", cfg.GetString("layoutDir")) assert.Equal("layouts", cfg.GetString("layoutDir"))
// no themes
assert.False(cfg.IsSet("allThemes"))
} }
func TestLoadMultiConfig(t *testing.T) { func TestLoadMultiConfig(t *testing.T) {