mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02: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:
@@ -83,46 +83,19 @@ func newHugoSites(cfg deps.DepsCfg, sites ...*Site) (*HugoSites, error) {
|
||||
|
||||
h := &HugoSites{
|
||||
multilingual: langConfig,
|
||||
multihost: cfg.Cfg.GetBool("multihost"),
|
||||
Sites: sites}
|
||||
|
||||
for _, s := range sites {
|
||||
s.owner = h
|
||||
}
|
||||
|
||||
// TODO(bep)
|
||||
cfg.Cfg.Set("multilingual", sites[0].multilingualEnabled())
|
||||
|
||||
if err := applyDepsIfNeeded(cfg, sites...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
h.Deps = sites[0].Deps
|
||||
|
||||
// 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.
|
||||
var baseURLFromLang bool
|
||||
|
||||
for _, s := range sites {
|
||||
burl := s.Language.GetLocal("baseURL")
|
||||
if baseURLFromLang && burl == nil {
|
||||
return h, errors.New("baseURL must be set on all or none of the languages")
|
||||
}
|
||||
|
||||
if burl != nil {
|
||||
baseURLFromLang = true
|
||||
}
|
||||
}
|
||||
|
||||
if baseURLFromLang {
|
||||
for _, s := range sites {
|
||||
// TODO(bep) multihost check
|
||||
s.Info.defaultContentLanguageInSubdir = true
|
||||
s.Cfg.Set("defaultContentLanguageInSubdir", true)
|
||||
}
|
||||
h.multihost = true
|
||||
}
|
||||
|
||||
return h, nil
|
||||
}
|
||||
|
||||
@@ -237,8 +210,9 @@ func (h *HugoSites) reset() {
|
||||
}
|
||||
|
||||
func (h *HugoSites) createSitesFromConfig() error {
|
||||
oldLangs, _ := h.Cfg.Get("languagesSorted").(helpers.Languages)
|
||||
|
||||
if err := loadLanguageSettings(h.Cfg); err != nil {
|
||||
if err := loadLanguageSettings(h.Cfg, oldLangs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -269,6 +243,7 @@ func (h *HugoSites) createSitesFromConfig() error {
|
||||
h.Deps = sites[0].Deps
|
||||
|
||||
h.multilingual = langConfig
|
||||
h.multihost = h.Deps.Cfg.GetBool("multihost")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user