mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 00:02:08 -05:00
hugolib: Add validation for defaultContentLanguage
When `languages` are defined, then `defaultContentLanguage` must match one of those. Fixes #4298
This commit is contained in:
parent
cd77968284
commit
4d5e4f379a
1 changed files with 16 additions and 0 deletions
|
@ -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("languagesSorted", langs)
|
||||||
cfg.Set("multilingual", len(langs) > 1)
|
cfg.Set("multilingual", len(langs) > 1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue