mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 19:02:07 -05:00
Do not call watchConfig() when not in watch mode
See #1772 Also, force DisableLiveReload to true when running "hugo --watch" (build-only non-server mode) to prevent livereload.ForceRefresh(), which would end up blocking watchConfig() forever, from being called because livereload.Initialize() is never called in this case. This fixes the bug where "hugo --watch" could only reload config.toml once before it gets stuck for good at livereload.ForceRefresh(). This is also consistent with Hugo's existing behaviour: Non-server "hugo --watch" has never injected livereload.js since the inception of the "watch" feature in Hugo v0.12.
This commit is contained in:
parent
c438f45629
commit
e8eb618166
1 changed files with 9 additions and 6 deletions
|
@ -90,7 +90,8 @@ func isUserError(err error) bool {
|
||||||
return userErrorRegexp.MatchString(err.Error())
|
return userErrorRegexp.MatchString(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
//HugoCmd is Hugo's root command. Every other command attached to HugoCmd is a child command to it.
|
// HugoCmd is Hugo's root command.
|
||||||
|
// Every other command attached to HugoCmd is a child command to it.
|
||||||
var HugoCmd = &cobra.Command{
|
var HugoCmd = &cobra.Command{
|
||||||
Use: "hugo",
|
Use: "hugo",
|
||||||
Short: "hugo builds your site",
|
Short: "hugo builds your site",
|
||||||
|
@ -105,10 +106,12 @@ Complete documentation is available at http://gohugo.io/.`,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if BuildWatch {
|
||||||
|
viper.Set("DisableLiveReload", true)
|
||||||
watchConfig()
|
watchConfig()
|
||||||
|
}
|
||||||
|
|
||||||
return build()
|
return build()
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +415,7 @@ func watchConfig() {
|
||||||
fmt.Println("Config file changed:", e.Name)
|
fmt.Println("Config file changed:", e.Name)
|
||||||
utils.CheckErr(buildSite(true))
|
utils.CheckErr(buildSite(true))
|
||||||
if !viper.GetBool("DisableLiveReload") {
|
if !viper.GetBool("DisableLiveReload") {
|
||||||
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initalized
|
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initialized
|
||||||
livereload.ForceRefresh()
|
livereload.ForceRefresh()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -777,7 +780,7 @@ func NewWatcher(port int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !BuildWatch && !viper.GetBool("DisableLiveReload") {
|
if !BuildWatch && !viper.GetBool("DisableLiveReload") {
|
||||||
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initalized
|
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initialized
|
||||||
|
|
||||||
// force refresh when more than one file
|
// force refresh when more than one file
|
||||||
if len(staticEvents) > 0 {
|
if len(staticEvents) > 0 {
|
||||||
|
@ -800,7 +803,7 @@ func NewWatcher(port int) error {
|
||||||
rebuildSite(dynamicEvents)
|
rebuildSite(dynamicEvents)
|
||||||
|
|
||||||
if !BuildWatch && !viper.GetBool("DisableLiveReload") {
|
if !BuildWatch && !viper.GetBool("DisableLiveReload") {
|
||||||
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initalized
|
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initialized
|
||||||
livereload.ForceRefresh()
|
livereload.ForceRefresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue