Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-08-06 15:51:50 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-06 18:32:17 +0300
commit596e0e98e4483d2a0a709412a338ceddb6538757 (patch)
tree0f8b33f98aa67dcb6fed48095b47ddd565575960 /commands
parent7cac19b1e3d2631395b88998b523a5a6d84b9e29 (diff)
Make it possible to add a language in server mode
See #2309
Diffstat (limited to 'commands')
-rw-r--r--commands/benchmark.go6
-rw-r--r--commands/hugo.go43
2 files changed, 32 insertions, 17 deletions
diff --git a/commands/benchmark.go b/commands/benchmark.go
index 56a50578b..b24d06ff4 100644
--- a/commands/benchmark.go
+++ b/commands/benchmark.go
@@ -57,8 +57,7 @@ func benchmark(cmd *cobra.Command, args []string) error {
return err
}
for i := 0; i < benchmarkTimes; i++ {
- _ = buildSites()
- Hugo.Reset()
+ _ = resetAndbuildSites(false)
}
pprof.WriteHeapProfile(f)
f.Close()
@@ -76,8 +75,7 @@ func benchmark(cmd *cobra.Command, args []string) error {
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
for i := 0; i < benchmarkTimes; i++ {
- _ = buildSites()
- Hugo.Reset()
+ _ = resetAndbuildSites(false)
}
}
diff --git a/commands/hugo.go b/commands/hugo.go
index eb6beebd1..723441911 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -419,14 +419,6 @@ func InitializeConfig(subCmdVs ...*cobra.Command) error {
helpers.HugoReleaseVersion(), minVersion)
}
- h, err := hugolib.NewHugoSitesFromConfiguration()
-
- if err != nil {
- return err
- }
- //TODO(bep) ml refactor ...
- Hugo = h
-
return nil
}
@@ -444,8 +436,7 @@ func watchConfig() {
viper.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("Config file changed:", e.Name)
// Force a full rebuild
- Hugo.Reset()
- utils.CheckErr(buildSites(true))
+ utils.CheckErr(reCreateAndbuildSites(true))
if !viper.GetBool("DisableLiveReload") {
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initialized
livereload.ForceRefresh()
@@ -638,13 +629,39 @@ func getDirList() []string {
return a
}
-func buildSites(watching ...bool) (err error) {
+func reCreateAndbuildSites(watching bool) (err error) {
+ fmt.Println("Started building sites ...")
+ return Hugo.Build(hugolib.BuildCfg{CreateSitesFromConfig: true, Watching: watching, PrintStats: true})
+}
+
+func resetAndbuildSites(watching bool) (err error) {
+ fmt.Println("Started building sites ...")
+ return Hugo.Build(hugolib.BuildCfg{ResetState: true, Watching: watching, PrintStats: true})
+}
+
+func initSites() error {
+ if Hugo != nil {
+ return nil
+ }
+
+ h, err := hugolib.NewHugoSitesFromConfiguration()
+
+ if err != nil {
+ return err
+ }
+ Hugo = h
+
+ return nil
+}
+
+func buildSites(watching bool) (err error) {
+ initSites()
fmt.Println("Started building sites ...")
- w := len(watching) > 0 && watching[0]
- return Hugo.Build(hugolib.BuildCfg{Watching: w, PrintStats: true})
+ return Hugo.Build(hugolib.BuildCfg{Watching: watching, PrintStats: true})
}
func rebuildSites(events []fsnotify.Event) error {
+ initSites()
return Hugo.Rebuild(hugolib.BuildCfg{PrintStats: true}, events...)
}