summaryrefslogtreecommitdiffstats
path: root/helpers/pathspec.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-11-12 10:03:56 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-11-17 11:01:46 +0100
commit60dfb9a6e076200ab3ca3fd30e34bb3c14e0a893 (patch)
tree810d3d7ca40a55045fec4a0718eb7728621495e4 /helpers/pathspec.go
parent2e0465764b5dacc511b977b1c9aa07324ad0ee9c (diff)
Add support for multiple staticDirs
This commit adds support for multiple statDirs both on the global and language level. A simple `config.toml` example: ```bash staticDir = ["static1", "static2"] [languages] [languages.no] staticDir = ["staticDir_override", "static_no"] baseURL = "https://example.no" languageName = "Norsk" weight = 1 title = "På norsk" [languages.en] staticDir2 = "static_en" baseURL = "https://example.com" languageName = "English" weight = 2 title = "In English" ``` In the above, with no theme used: the English site will get its static files as a union of "static1", "static2" and "static_en". On file duplicates, the right-most version will win. the Norwegian site will get its static files as a union of "staticDir_override" and "static_no". This commit also concludes the Multihost support in #4027. Fixes #36 Closes #4027
Diffstat (limited to 'helpers/pathspec.go')
-rw-r--r--helpers/pathspec.go46
1 files changed, 43 insertions, 3 deletions
diff --git a/helpers/pathspec.go b/helpers/pathspec.go
index 643d05646..5b7f534fe 100644
--- a/helpers/pathspec.go
+++ b/helpers/pathspec.go
@@ -40,7 +40,7 @@ type PathSpec struct {
themesDir string
layoutDir string
workingDir string
- staticDir string
+ staticDirs []string
// The PathSpec looks up its config settings in both the current language
// and then in the global Viper config.
@@ -72,6 +72,12 @@ func NewPathSpec(fs *hugofs.Fs, cfg config.Provider) (*PathSpec, error) {
return nil, fmt.Errorf("Failed to create baseURL from %q: %s", baseURLstr, err)
}
+ var staticDirs []string
+
+ for i := -1; i <= 10; i++ {
+ staticDirs = append(staticDirs, getStringOrStringSlice(cfg, "staticDir", i)...)
+ }
+
ps := &PathSpec{
Fs: fs,
Cfg: cfg,
@@ -87,7 +93,7 @@ func NewPathSpec(fs *hugofs.Fs, cfg config.Provider) (*PathSpec, error) {
themesDir: cfg.GetString("themesDir"),
layoutDir: cfg.GetString("layoutDir"),
workingDir: cfg.GetString("workingDir"),
- staticDir: cfg.GetString("staticDir"),
+ staticDirs: staticDirs,
theme: cfg.GetString("theme"),
}
@@ -98,6 +104,25 @@ func NewPathSpec(fs *hugofs.Fs, cfg config.Provider) (*PathSpec, error) {
return ps, nil
}
+func getStringOrStringSlice(cfg config.Provider, key string, id int) []string {
+
+ if id > 0 {
+ key = fmt.Sprintf("%s%d", key, id)
+ }
+
+ var out []string
+
+ sd := cfg.Get(key)
+
+ if sds, ok := sd.(string); ok {
+ out = []string{sds}
+ } else if sdsl, ok := sd.([]string); ok {
+ out = sdsl
+ }
+
+ return out
+}
+
// PaginatePath returns the configured root path used for paginator pages.
func (p *PathSpec) PaginatePath() string {
return p.paginatePath
@@ -108,7 +133,17 @@ func (p *PathSpec) WorkingDir() string {
return p.workingDir
}
-// LayoutDir returns the relative layout dir in the currenct Hugo project.
+// StaticDir returns the relative static dir in the current configuration.
+func (p *PathSpec) StaticDir() string {
+ return p.staticDirs[len(p.staticDirs)-1]
+}
+
+// StaticDirs returns the relative static dirs for the current configuration.
+func (p *PathSpec) StaticDirs() []string {
+ return p.staticDirs
+}
+
+// LayoutDir returns the relative layout dir in the current configuration.
func (p *PathSpec) LayoutDir() string {
return p.layoutDir
}
@@ -117,3 +152,8 @@ func (p *PathSpec) LayoutDir() string {
func (p *PathSpec) Theme() string {
return p.theme
}
+
+// Theme returns the theme relative theme dir.
+func (p *PathSpec) ThemesDir() string {
+ return p.themesDir
+}