summaryrefslogtreecommitdiffhomepage
path: root/helpers
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2017-11-02 08:25:20 +0100
committerBjørn Erik Pedersen <[email protected]>2017-11-17 11:01:46 +0100
commit2e0465764b5dacc511b977b1c9aa07324ad0ee9c (patch)
treeae5a32eb9340e4c0e78e063228821edc29037631 /helpers
parent6233ddf9d19b51f69c0c4a796d88732d1700e585 (diff)
downloadhugo-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')
-rw-r--r--helpers/language.go24
-rw-r--r--helpers/path.go1
2 files changed, 23 insertions, 2 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.
diff --git a/helpers/path.go b/helpers/path.go
index fccba2238..a9e2567c6 100644
--- a/helpers/path.go
+++ b/helpers/path.go
@@ -158,7 +158,6 @@ func (p *PathSpec) AbsPathify(inPath string) string {
return filepath.Clean(inPath)
}
- // TODO(bep): Consider moving workingDir to argument list
return filepath.Join(p.workingDir, inPath)
}