diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-04-04 09:29:59 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-04-04 09:29:59 +0200 |
commit | 730b66b6520f263af16f555d1d7be51205a8e51d (patch) | |
tree | ddad821969aa76ac5211b32ec045e138f51854ae /commands/hugo.go | |
parent | 4f639d6bd5ea47a28005d722227660d076299243 (diff) | |
download | hugo-730b66b6520f263af16f555d1d7be51205a8e51d.tar.gz hugo-730b66b6520f263af16f555d1d7be51205a8e51d.zip |
commands: Handle mass content etc. edits in server mode
Fixes #4563
Diffstat (limited to 'commands/hugo.go')
-rw-r--r-- | commands/hugo.go | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/commands/hugo.go b/commands/hugo.go index ba8c0aef4..d0894a11a 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -851,6 +851,16 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error { return Hugo.Build(hugolib.BuildCfg{RecentlyVisited: visited}, events...) } +func (c *commandeer) fullRebuild() { + if err := c.loadConfig(true); err != nil { + jww.ERROR.Println("Failed to reload config:", err) + } else if err := c.recreateAndBuildSites(true); err != nil { + jww.ERROR.Println(err) + } else if !buildWatch && !c.Cfg.GetBool("disableLiveReload") { + livereload.ForceRefresh() + } +} + // newWatcher creates a new watcher to watch filesystem events. func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) { if runtime.GOOS == "darwin" { @@ -887,6 +897,13 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) { for { select { case evs := <-watcher.Events: + if len(evs) > 50 { + // This is probably a mass edit of the content dir. + // Schedule a full rebuild for when it slows down. + c.debounce(c.fullRebuild) + continue + } + c.Logger.INFO.Println("Received System Events:", evs) staticEvents := []fsnotify.Event{} @@ -900,13 +917,7 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) { continue } // Config file changed. Need full rebuild. - if err := c.loadConfig(true); err != nil { - jww.ERROR.Println("Failed to reload config:", err) - } else if err := c.recreateAndBuildSites(true); err != nil { - jww.ERROR.Println(err) - } else if !buildWatch && !c.Cfg.GetBool("disableLiveReload") { - livereload.ForceRefresh() - } + c.fullRebuild() break } |