diff options
Diffstat (limited to 'commands/hugobuilder.go')
-rw-r--r-- | commands/hugobuilder.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/commands/hugobuilder.go b/commands/hugobuilder.go index 32b7e1de8..99bd8a04a 100644 --- a/commands/hugobuilder.go +++ b/commands/hugobuilder.go @@ -43,6 +43,7 @@ import ( "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/hugolib" "github.com/gohugoio/hugo/hugolib/filesystems" + "github.com/gohugoio/hugo/identity" "github.com/gohugoio/hugo/livereload" "github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/watcher" @@ -343,6 +344,24 @@ func (c *hugoBuilder) newWatcher(pollIntervalStr string, dirList ...string) (*wa go func() { for { select { + case changes := <-c.r.changesFromBuild: + unlock, err := h.LockBuild() + if err != nil { + c.r.logger.Errorln("Failed to acquire a build lock: %s", err) + return + } + c.changeDetector.PrepareNew() + err = c.rebuildSitesForChanges(changes) + if err != nil { + c.r.logger.Errorln("Error while watching:", err) + } + if c.s != nil && c.s.doLiveReload { + if c.changeDetector == nil || len(c.changeDetector.changed()) > 0 { + livereload.ForceRefresh() + } + } + unlock() + case evs := <-watcher.Events: unlock, err := h.LockBuild() if err != nil { @@ -1019,6 +1038,19 @@ func (c *hugoBuilder) rebuildSites(events []fsnotify.Event) error { return h.Build(hugolib.BuildCfg{NoBuildLock: true, RecentlyVisited: c.visitedURLs, ErrRecovery: c.errState.wasErr()}, events...) } +func (c *hugoBuilder) rebuildSitesForChanges(ids []identity.Identity) error { + c.errState.setBuildErr(nil) + h, err := c.hugo() + if err != nil { + return err + } + whatChanged := &hugolib.WhatChanged{} + whatChanged.Add(ids...) + err = h.Build(hugolib.BuildCfg{NoBuildLock: true, WhatChanged: whatChanged, RecentlyVisited: c.visitedURLs, ErrRecovery: c.errState.wasErr()}) + c.errState.setBuildErr(err) + return err +} + func (c *hugoBuilder) reloadConfig() error { c.r.Reset() c.r.configVersionID.Add(1) |