diff options
author | Bjørn Erik Pedersen <[email protected]> | 2017-11-02 08:25:20 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2017-11-17 11:01:46 +0100 |
commit | 2e0465764b5dacc511b977b1c9aa07324ad0ee9c (patch) | |
tree | ae5a32eb9340e4c0e78e063228821edc29037631 /helpers/language.go | |
parent | 6233ddf9d19b51f69c0c4a796d88732d1700e585 (diff) | |
download | hugo-2e0465764b5dacc511b977b1c9aa07324ad0ee9c.tar.gz hugo-2e0465764b5dacc511b977b1c9aa07324ad0ee9c.zip |
Add multilingual multihost support
This commit adds multihost support when more than one language is configured and `baseURL` is set per language.
Updates #4027
Diffstat (limited to 'helpers/language.go')
-rw-r--r-- | helpers/language.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/helpers/language.go b/helpers/language.go index 6b4119a9b..d9f3f69ed 100644 --- a/helpers/language.go +++ b/helpers/language.go @@ -102,6 +102,17 @@ func (l *Language) Params() map[string]interface{} { return l.params } +// IsMultihost returns whether the languages has baseURL specificed on the +// language level. +func (l Languages) IsMultihost() bool { + for _, lang := range l { + if lang.GetLocal("baseURL") != nil { + return true + } + } + return false +} + // SetParam sets param with the given key and value. // SetParam is case-insensitive. func (l *Language) SetParam(k string, v interface{}) { @@ -132,6 +143,17 @@ func (l *Language) GetStringMapString(key string) map[string]string { // // Get returns an interface. For a specific value use one of the Get____ methods. func (l *Language) Get(key string) interface{} { + local := l.GetLocal(key) + if local != nil { + return local + } + return l.Cfg.Get(key) +} + +// GetLocal gets a configuration value set on language level. It will +// not fall back to any global value. +// It will return nil if a value with the given key cannot be found. +func (l *Language) GetLocal(key string) interface{} { if l == nil { panic("language not set") } @@ -141,7 +163,7 @@ func (l *Language) Get(key string) interface{} { return v } } - return l.Cfg.Get(key) + return nil } // Set sets the value for the key in the language's params. |