mirror of
https://github.com/gohugoio/hugo.git
synced 2025-02-10 22:21:37 +00:00
parent
4f639d6bd5
commit
730b66b652
4 changed files with 45 additions and 9 deletions
8
Gopkg.lock
generated
8
Gopkg.lock
generated
|
@ -57,6 +57,12 @@
|
||||||
]
|
]
|
||||||
revision = "85c342e3e3d715ad780edd0ba8728161e99cce24"
|
revision = "85c342e3e3d715ad780edd0ba8728161e99cce24"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/bep/debounce"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "4d3a5ad34e592abc468ed5c6b2a23fcca372ebcd"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/bep/gitmap"
|
name = "github.com/bep/gitmap"
|
||||||
|
@ -424,6 +430,6 @@
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "edb250b53926de21df1740c379c76351b7e9b110c96a77078a10ba69bf31a2d4"
|
inputs-digest = "49464f23053ef206ad23f65c511943ef50f188a1d0023db3ac5223051a3bba78"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
|
@ -145,3 +145,7 @@
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/sanity-io/litter"
|
name = "github.com/sanity-io/litter"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/bep/debounce"
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ import (
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/hugolib"
|
"github.com/gohugoio/hugo/hugolib"
|
||||||
|
|
||||||
|
"github.com/bep/debounce"
|
||||||
"github.com/gohugoio/hugo/common/types"
|
"github.com/gohugoio/hugo/common/types"
|
||||||
"github.com/gohugoio/hugo/deps"
|
"github.com/gohugoio/hugo/deps"
|
||||||
"github.com/gohugoio/hugo/helpers"
|
"github.com/gohugoio/hugo/helpers"
|
||||||
|
@ -51,6 +53,9 @@ type commandeer struct {
|
||||||
// We can do this only once.
|
// We can do this only once.
|
||||||
fsCreate sync.Once
|
fsCreate sync.Once
|
||||||
|
|
||||||
|
// Used in cases where we get flooded with events in server mode.
|
||||||
|
debounce func(f func())
|
||||||
|
|
||||||
serverPorts []int
|
serverPorts []int
|
||||||
languages helpers.Languages
|
languages helpers.Languages
|
||||||
|
|
||||||
|
@ -90,10 +95,20 @@ func (c *commandeer) initFs(fs *hugofs.Fs) error {
|
||||||
|
|
||||||
func newCommandeer(running bool, doWithCommandeer func(c *commandeer) error, subCmdVs ...*cobra.Command) (*commandeer, error) {
|
func newCommandeer(running bool, doWithCommandeer func(c *commandeer) error, subCmdVs ...*cobra.Command) (*commandeer, error) {
|
||||||
|
|
||||||
|
var rebuildDebouncer func(f func())
|
||||||
|
if running {
|
||||||
|
// The time value used is tested with mass content replacements in a fairly big Hugo site.
|
||||||
|
// It is better to wait for some seconds in those cases rather than get flooded
|
||||||
|
// with rebuilds.
|
||||||
|
rebuildDebouncer, _ = debounce.New(4 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
c := &commandeer{
|
c := &commandeer{
|
||||||
doWithCommandeer: doWithCommandeer,
|
doWithCommandeer: doWithCommandeer,
|
||||||
subCmdVs: append([]*cobra.Command{hugoCmdV}, subCmdVs...),
|
subCmdVs: append([]*cobra.Command{hugoCmdV}, subCmdVs...),
|
||||||
visitedURLs: types.NewEvictingStringQueue(10)}
|
visitedURLs: types.NewEvictingStringQueue(10),
|
||||||
|
debounce: rebuildDebouncer,
|
||||||
|
}
|
||||||
|
|
||||||
return c, c.loadConfig(running)
|
return c, c.loadConfig(running)
|
||||||
}
|
}
|
||||||
|
|
|
@ -851,6 +851,16 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error {
|
||||||
return Hugo.Build(hugolib.BuildCfg{RecentlyVisited: visited}, events...)
|
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.
|
// newWatcher creates a new watcher to watch filesystem events.
|
||||||
func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
|
func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
|
@ -887,6 +897,13 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case evs := <-watcher.Events:
|
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)
|
c.Logger.INFO.Println("Received System Events:", evs)
|
||||||
|
|
||||||
staticEvents := []fsnotify.Event{}
|
staticEvents := []fsnotify.Event{}
|
||||||
|
@ -900,13 +917,7 @@ func (c *commandeer) newWatcher(dirList ...string) (*watcher.Batcher, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Config file changed. Need full rebuild.
|
// Config file changed. Need full rebuild.
|
||||||
if err := c.loadConfig(true); err != nil {
|
c.fullRebuild()
|
||||||
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()
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue