Skip to content

Commit 4d5e4f3

Browse files
committed
hugolib: Add validation for defaultContentLanguage
When `languages` are defined, then `defaultContentLanguage` must match one of those. Fixes #4298
1 parent cd77968 commit 4d5e4f3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎hugolib/config.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ func loadLanguageSettings(cfg config.Provider, oldLangs helpers.Languages) error
131131
}
132132
}
133133

134+
defaultLang := cfg.GetString("defaultContentLanguage")
135+
136+
// The defaultContentLanguage is something the user has to decide, but it needs
137+
// to match a language in the language definition list.
138+
langExists := false
139+
for _, lang := range langs {
140+
if lang.Lang == defaultLang {
141+
langExists = true
142+
break
143+
}
144+
}
145+
146+
if !langExists {
147+
return fmt.Errorf("site config value %q for defaultContentLanguage does not match any language definition", defaultLang)
148+
}
149+
134150
cfg.Set("languagesSorted", langs)
135151
cfg.Set("multilingual", len(langs) > 1)
136152

0 commit comments

Comments
 (0)