hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 4d5e4f379a890a3c6cbc11ddb40d77a90f14c015
parent cd77968284c64525c351f0b99466ad2ef29657e5
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Fri, 19 Jan 2018 08:24:10 +0100

hugolib: Add validation for defaultContentLanguage

When `languages` are defined, then `defaultContentLanguage` must match one of those.

Fixes #4298

Diffstat:
Mhugolib/config.go | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git a/hugolib/config.go b/hugolib/config.go
@@ -131,6 +131,22 @@ func loadLanguageSettings(cfg config.Provider, oldLangs helpers.Languages) error
 		}
 	}
 
+	defaultLang := cfg.GetString("defaultContentLanguage")
+
+	// The defaultContentLanguage is something the user has to decide, but it needs
+	// to match a language in the language definition list.
+	langExists := false
+	for _, lang := range langs {
+		if lang.Lang == defaultLang {
+			langExists = true
+			break
+		}
+	}
+
+	if !langExists {
+		return fmt.Errorf("site config value %q for defaultContentLanguage does not match any language definition", defaultLang)
+	}
+
 	cfg.Set("languagesSorted", langs)
 	cfg.Set("multilingual", len(langs) > 1)