mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +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:
@@ -14,6 +14,7 @@
|
||||
package hugolib
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"io"
|
||||
@@ -88,7 +89,7 @@ func LoadConfig(fs afero.Fs, relativeSourcePath, configFilename string) (*viper.
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func loadLanguageSettings(cfg config.Provider) error {
|
||||
func loadLanguageSettings(cfg config.Provider, oldLangs helpers.Languages) error {
|
||||
multilingual := cfg.GetStringMap("languages")
|
||||
var (
|
||||
langs helpers.Languages
|
||||
@@ -104,7 +105,56 @@ func loadLanguageSettings(cfg config.Provider) error {
|
||||
}
|
||||
}
|
||||
|
||||
if oldLangs != nil {
|
||||
// When in multihost mode, the languages are mapped to a server, so
|
||||
// some structural language changes will need a restart of the dev server.
|
||||
// The validation below isn't complete, but should cover the most
|
||||
// important cases.
|
||||
var invalid bool
|
||||
if langs.IsMultihost() != oldLangs.IsMultihost() {
|
||||
invalid = true
|
||||
} else {
|
||||
if langs.IsMultihost() && len(langs) != len(oldLangs) {
|
||||
invalid = true
|
||||
}
|
||||
}
|
||||
|
||||
if invalid {
|
||||
return errors.New("language change needing a server restart detected")
|
||||
}
|
||||
|
||||
if langs.IsMultihost() {
|
||||
// We need to transfer any server baseURL to the new language
|
||||
for i, ol := range oldLangs {
|
||||
nl := langs[i]
|
||||
nl.Set("baseURL", ol.GetString("baseURL"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cfg.Set("languagesSorted", langs)
|
||||
cfg.Set("multilingual", len(langs) > 1)
|
||||
|
||||
// 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 _, l := range langs {
|
||||
burl := l.GetLocal("baseURL")
|
||||
if baseURLFromLang && burl == nil {
|
||||
return errors.New("baseURL must be set on all or none of the languages")
|
||||
}
|
||||
|
||||
if burl != nil {
|
||||
baseURLFromLang = true
|
||||
}
|
||||
}
|
||||
|
||||
if baseURLFromLang {
|
||||
cfg.Set("defaultContentLanguageInSubdir", true)
|
||||
cfg.Set("multihost", true)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -178,5 +228,5 @@ func loadDefaultSettingsFor(v *viper.Viper) error {
|
||||
v.SetDefault("debug", false)
|
||||
v.SetDefault("disableFastRender", false)
|
||||
|
||||
return loadLanguageSettings(v)
|
||||
return loadLanguageSettings(v, nil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user