mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 14:10:31 +03:00
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
This commit is contained in:
parent
2e0465764b
commit
60dfb9a6e0
25 changed files with 825 additions and 273 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue