diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-08 20:00:05 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-08 20:14:28 +0200 |
commit | fe901b81191860b60e6fcb29f8ebf87baef2ee79 (patch) | |
tree | d2a3d58c28f826b602f81973fc0e7dbaec4c697b /commands/hugo.go | |
parent | b39689393ccb8434d9a57658a64b77568c718e99 (diff) |
hugolib, commands: Improve live-reload on directory structure changes
This issue is more visible now that we support nested sections.
This commit makes operations like pasting new content folders or deleting content folders during server watch just work.
Fixes #3570
Diffstat (limited to 'commands/hugo.go')
-rw-r--r-- | commands/hugo.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/commands/hugo.go b/commands/hugo.go index eaf75e329..9b827bc9b 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -829,6 +829,11 @@ func (c *commandeer) newWatcher(port int) error { if err := watcher.Add(path); err != nil { return err } + } else if !c.isStatic(path) { + // Hugo's rebuilding logic is entirely file based. When you drop a new folder into + // /content on OSX, the above logic will handle future watching of those files, + // but the initial CREATE is lost. + dynamicEvents = append(dynamicEvents, fsnotify.Event{Name: path, Op: fsnotify.Create}) } return nil } @@ -841,9 +846,7 @@ func (c *commandeer) newWatcher(port int) error { } } - isstatic := strings.HasPrefix(ev.Name, c.PathSpec().GetStaticDirPath()) || (len(c.PathSpec().GetThemesDirPath()) > 0 && strings.HasPrefix(ev.Name, c.PathSpec().GetThemesDirPath())) - - if isstatic { + if c.isStatic(ev.Name) { staticEvents = append(staticEvents, ev) } else { dynamicEvents = append(dynamicEvents, ev) @@ -999,6 +1002,10 @@ func (c *commandeer) newWatcher(port int) error { return nil } +func (c *commandeer) isStatic(path string) bool { + return strings.HasPrefix(path, c.PathSpec().GetStaticDirPath()) || (len(c.PathSpec().GetThemesDirPath()) > 0 && strings.HasPrefix(path, c.PathSpec().GetThemesDirPath())) +} + // isThemeVsHugoVersionMismatch returns whether the current Hugo version is // less than the theme's min_version. func (c *commandeer) isThemeVsHugoVersionMismatch() (mismatch bool, requiredMinVersion string) { |