hugolib: Only set 'allThemes' if there are themes in the config file
authorGarry McNulty <garrmcnu@gmail.com>
Sun, 15 Jul 2018 13:35:41 +0000 (14:35 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 15 Jul 2018 14:13:48 +0000 (16:13 +0200)
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

hugolib/config.go
hugolib/config_test.go

index 87f97f3a51d8f59d82661c376ff67df020631c55..122bd3f1e04d2910479442dbe2b71ce2ffb87ec7 100644 (file)
@@ -285,6 +285,11 @@ func loadThemeConfig(d ConfigSourceDescriptor, v1 *viper.Viper) ([]string, error
        if err != nil {
                return nil, err
        }
+
+       if len(themeConfigs) == 0 {
+               return nil, nil
+       }
+
        v1.Set("allThemes", themeConfigs)
 
        var configFilenames []string
index 2fa26d4f3b3feb63b43d41f6bdf79d977e5dede8..0fe692805c4b0deab8c046732157b1a6f0bb2dca 100644 (file)
@@ -42,6 +42,8 @@ func TestLoadConfig(t *testing.T) {
        assert.Equal("side", cfg.GetString("paginatePath"))
        // default
        assert.Equal("layouts", cfg.GetString("layoutDir"))
+       // no themes
+       assert.False(cfg.IsSet("allThemes"))
 }
 
 func TestLoadMultiConfig(t *testing.T) {