mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Optimize the multilanguage build process
Work In Progress! This commit makes a rework of the build and rebuild process to better suit a multi-site setup. This also includes a complete overhaul of the site tests. Previous these were a messy mix that were testing just small parts of the build chain, some of it testing code-paths not even used in "real life". Now all tests that depends on a built site follows the same and real production code path. See #2309 Closes #2211 Closes #477 Closes #1744
This commit is contained in:
@@ -49,7 +49,7 @@ import (
|
||||
// Hugo represents the Hugo sites to build. This variable is exported as it
|
||||
// is used by at least one external library (the Hugo caddy plugin). We should
|
||||
// provide a cleaner external API, but until then, this is it.
|
||||
var Hugo hugolib.HugoSites
|
||||
var Hugo *hugolib.HugoSites
|
||||
|
||||
// Reset resets Hugo ready for a new full build. This is mainly only useful
|
||||
// for benchmark testing etc. via the CLI commands.
|
||||
@@ -715,11 +715,11 @@ func getDirList() []string {
|
||||
func buildSites(watching ...bool) (err error) {
|
||||
fmt.Println("Started building sites ...")
|
||||
w := len(watching) > 0 && watching[0]
|
||||
return Hugo.Build(w, true)
|
||||
return Hugo.Build(hugolib.BuildCfg{Watching: w, PrintStats: true})
|
||||
}
|
||||
|
||||
func rebuildSites(events []fsnotify.Event) error {
|
||||
return Hugo.Rebuild(events, true)
|
||||
return Hugo.Rebuild(hugolib.BuildCfg{PrintStats: true}, events...)
|
||||
}
|
||||
|
||||
// NewWatcher creates a new watcher to watch filesystem events.
|
||||
|
@@ -53,7 +53,7 @@ var listDraftsCmd = &cobra.Command{
|
||||
|
||||
site := &hugolib.Site{}
|
||||
|
||||
if err := site.Process(); err != nil {
|
||||
if err := site.PreProcess(hugolib.BuildCfg{}); err != nil {
|
||||
return newSystemError("Error Processing Source Content", err)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ posted in the future.`,
|
||||
|
||||
site := &hugolib.Site{}
|
||||
|
||||
if err := site.Process(); err != nil {
|
||||
if err := site.PreProcess(hugolib.BuildCfg{}); err != nil {
|
||||
return newSystemError("Error Processing Source Content", err)
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ expired.`,
|
||||
|
||||
site := &hugolib.Site{}
|
||||
|
||||
if err := site.Process(); err != nil {
|
||||
if err := site.PreProcess(hugolib.BuildCfg{}); err != nil {
|
||||
return newSystemError("Error Processing Source Content", err)
|
||||
}
|
||||
|
||||
|
@@ -11,30 +11,31 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func readMultilingualConfiguration() (hugolib.HugoSites, error) {
|
||||
h := make(hugolib.HugoSites, 0)
|
||||
func readMultilingualConfiguration() (*hugolib.HugoSites, error) {
|
||||
sites := make([]*hugolib.Site, 0)
|
||||
multilingual := viper.GetStringMap("Multilingual")
|
||||
if len(multilingual) == 0 {
|
||||
// TODO(bep) multilingo langConfigsList = append(langConfigsList, hugolib.NewLanguage("en"))
|
||||
h = append(h, hugolib.NewSite(hugolib.NewLanguage("en")))
|
||||
return h, nil
|
||||
sites = append(sites, hugolib.NewSite(hugolib.NewLanguage("en")))
|
||||
}
|
||||
|
||||
var err error
|
||||
if len(multilingual) > 0 {
|
||||
var err error
|
||||
|
||||
langConfigsList, err := toSortedLanguages(multilingual)
|
||||
languages, err := toSortedLanguages(multilingual)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to parse multilingual config: %s", err)
|
||||
}
|
||||
|
||||
for _, lang := range languages {
|
||||
sites = append(sites, hugolib.NewSite(lang))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to parse multilingual config: %s", err)
|
||||
}
|
||||
|
||||
for _, lang := range langConfigsList {
|
||||
s := hugolib.NewSite(lang)
|
||||
s.SetMultilingualConfig(lang, langConfigsList)
|
||||
h = append(h, s)
|
||||
}
|
||||
return hugolib.NewHugoSites(sites...)
|
||||
|
||||
return h, nil
|
||||
}
|
||||
|
||||
func toSortedLanguages(l map[string]interface{}) (hugolib.Languages, error) {
|
||||
|
Reference in New Issue
Block a user