Fix multihost detection for sites without language definition

Static content was wrongly put into the lang-code subfolder.

Fixes #4221
This commit is contained in:
Bjørn Erik Pedersen 2018-01-06 18:42:32 +01:00
parent 6feb138785
commit 8969331f5b
2 changed files with 21 additions and 18 deletions

View file

@ -100,9 +100,13 @@ func (l *Language) Params() map[string]interface{} {
return l.params return l.params
} }
// IsMultihost returns whether the languages has baseURL specificed on the // IsMultihost returns whether there are more than one language and at least one of
// language level. // the languages has baseURL specificed on the language level.
func (l Languages) IsMultihost() bool { func (l Languages) IsMultihost() bool {
if len(l) <= 1 {
return false
}
for _, lang := range l { for _, lang := range l {
if lang.GetLocal("baseURL") != nil { if lang.GetLocal("baseURL") != nil {
return true return true

View file

@ -134,27 +134,26 @@ func loadLanguageSettings(cfg config.Provider, oldLangs helpers.Languages) error
cfg.Set("languagesSorted", langs) cfg.Set("languagesSorted", langs)
cfg.Set("multilingual", len(langs) > 1) cfg.Set("multilingual", len(langs) > 1)
// The baseURL may be provided at the language level. If that is true, multihost := langs.IsMultihost()
// then every language must have a baseURL. In this case we always render
// to a language sub folder, which is then stripped from all the Permalink URLs etc.
var baseURLFromLang bool
for _, l := range langs { if multihost {
burl := l.GetLocal("baseURL")
if baseURLFromLang && burl == nil {
return errors.New("baseURL must be set on all or none of the languages")
}
if burl != nil {
baseURLFromLang = true
}
}
if baseURLFromLang {
cfg.Set("defaultContentLanguageInSubdir", true) cfg.Set("defaultContentLanguageInSubdir", true)
cfg.Set("multihost", true) cfg.Set("multihost", true)
} }
if multihost {
// The baseURL may be provided at the language level. If that is true,
// then every language must have a baseURL. In this case we always render
// to a language sub folder, which is then stripped from all the Permalink URLs etc.
for _, l := range langs {
burl := l.GetLocal("baseURL")
if burl == nil {
return errors.New("baseURL must be set on all or none of the languages")
}
}
}
return nil return nil
} }