summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-06-08 20:00:05 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-06-08 20:14:28 +0200
commitfe901b81191860b60e6fcb29f8ebf87baef2ee79 (patch)
treed2a3d58c28f826b602f81973fc0e7dbaec4c697b /hugolib
parentb39689393ccb8434d9a57658a64b77568c718e99 (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 'hugolib')
-rw-r--r--hugolib/page.go12
-rw-r--r--hugolib/page_collections.go12
-rw-r--r--hugolib/site.go10
3 files changed, 29 insertions, 5 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index cb9a28f24..42ed4e60f 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -322,6 +322,18 @@ func (ps Pages) FindPagePosByFilePath(inPath string) int {
return -1
}
+func (ps Pages) FindPagePosByFilePathPrefix(prefix string) int {
+ if prefix == "" {
+ return -1
+ }
+ for i, x := range ps {
+ if strings.HasPrefix(x.Source.Path(), prefix) {
+ return i
+ }
+ }
+ return -1
+}
+
// FindPagePos Given a page, it will find the position in Pages
// will return -1 if not found
func (ps Pages) FindPagePos(page *Page) int {
diff --git a/hugolib/page_collections.go b/hugolib/page_collections.go
index 4360f9315..b31738846 100644
--- a/hugolib/page_collections.go
+++ b/hugolib/page_collections.go
@@ -137,6 +137,18 @@ func (c *PageCollections) addPage(page *Page) {
c.rawAllPages = append(c.rawAllPages, page)
}
+// When we get a REMOVE event we're not always getting all the individual files,
+// so we need to remove all below a given path.
+func (c *PageCollections) removePageByPathPrefix(path string) {
+ for {
+ i := c.rawAllPages.FindPagePosByFilePathPrefix(path)
+ if i == -1 {
+ break
+ }
+ c.rawAllPages = append(c.rawAllPages[:i], c.rawAllPages[i+1:]...)
+ }
+}
+
func (c *PageCollections) removePageByPath(path string) {
if i := c.rawAllPages.FindPagePosByFilePath(path); i >= 0 {
c.rawAllPages = append(c.rawAllPages[:i], c.rawAllPages[i+1:]...)
diff --git a/hugolib/site.go b/hugolib/site.go
index 929dd590f..a172edd6a 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -667,11 +667,11 @@ func (s *Site) reProcess(events []fsnotify.Event) (whatChanged, error) {
seen[ev] = true
if s.isContentDirEvent(ev) {
- logger.Println("Source changed", ev.Name)
+ logger.Println("Source changed", ev)
sourceChanged = append(sourceChanged, ev)
}
if s.isLayoutDirEvent(ev) {
- logger.Println("Template changed", ev.Name)
+ logger.Println("Template changed", ev)
tmplChanged = append(tmplChanged, ev)
if strings.Contains(ev.Name, "shortcodes") {
@@ -682,11 +682,11 @@ func (s *Site) reProcess(events []fsnotify.Event) (whatChanged, error) {
}
}
if s.isDataDirEvent(ev) {
- logger.Println("Data changed", ev.Name)
+ logger.Println("Data changed", ev)
dataChanged = append(dataChanged, ev)
}
if s.isI18nEvent(ev) {
- logger.Println("i18n changed", ev.Name)
+ logger.Println("i18n changed", ev)
i18nChanged = append(dataChanged, ev)
}
}
@@ -761,7 +761,7 @@ func (s *Site) reProcess(events []fsnotify.Event) (whatChanged, error) {
if ev.Op&fsnotify.Remove == fsnotify.Remove {
//remove the file & a create will follow
path, _ := helpers.GetRelativePath(ev.Name, s.getContentDir(ev.Name))
- s.removePageByPath(path)
+ s.removePageByPathPrefix(path)
continue
}