diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/commandeer.go | 5 | ||||
-rw-r--r-- | commands/hugo.go | 27 | ||||
-rw-r--r-- | commands/server.go | 14 |
3 files changed, 33 insertions, 13 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go index 2b76462fe..94b2c6553 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -324,10 +324,7 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { fs.Destination = new(afero.MemMapFs) } - doLiveReload := !c.h.buildWatch && !config.GetBool("disableLiveReload") - fastRenderMode := doLiveReload && !config.GetBool("disableFastRender") - - if fastRenderMode { + if c.fastRenderMode { // For now, fast render mode only. It should, however, be fast enough // for the full variant, too. changeDetector := &fileChangeDetector{ diff --git a/commands/hugo.go b/commands/hugo.go index 6cb2ec012..deaa1f7ff 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -618,13 +618,20 @@ func (c *commandeer) buildSites() (err error) { return c.hugo.Build(hugolib.BuildCfg{}) } +func (c *commandeer) handleBuildErr(err error, msg string) { + c.buildErr = err + c.logger.ERROR.Printf("%s: %s", msg, err) + if !c.h.quiet && c.h.verbose { + herrors.PrintStackTrace(err) + } +} + func (c *commandeer) rebuildSites(events []fsnotify.Event) error { defer c.timeTrack(time.Now(), "Total") c.buildErr = nil visited := c.visitedURLs.PeekAllSet() - doLiveReload := !c.h.buildWatch && !c.Cfg.GetBool("disableLiveReload") - if doLiveReload && !c.Cfg.GetBool("disableFastRender") { + if c.fastRenderMode { // Make sure we always render the home pages for _, l := range c.languages { @@ -640,6 +647,15 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error { return c.hugo.Build(hugolib.BuildCfg{RecentlyVisited: visited}, events...) } +func (c *commandeer) partialReRender(urls ...string) error { + c.buildErr = nil + visited := make(map[string]bool) + for _, url := range urls { + visited[url] = true + } + return c.hugo.Build(hugolib.BuildCfg{RecentlyVisited: visited, PartialReRender: true}) +} + func (c *commandeer) fullRebuild() { c.commandeerHugoState = &commandeerHugoState{} err := c.loadConfig(true, true) @@ -907,15 +923,10 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher, c.changeDetector.PrepareNew() if err := c.rebuildSites(dynamicEvents); err != nil { - c.buildErr = err - c.logger.ERROR.Printf("Rebuild failed: %s", err) - if !c.h.quiet && c.h.verbose { - herrors.PrintStackTrace(err) - } + c.handleBuildErr(err, "Rebuild failed") } if doLiveReload { - if len(partitionedEvents.ContentEvents) == 0 && len(partitionedEvents.AssetEvents) > 0 { changed := c.changeDetector.changed() if c.changeDetector != nil && len(changed) == 0 { diff --git a/commands/server.go b/commands/server.go index ffdbc95c9..7b7164eea 100644 --- a/commands/server.go +++ b/commands/server.go @@ -345,10 +345,22 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, string, erro w.Header().Set("Pragma", "no-cache") } - if f.c.fastRenderMode { + if f.c.fastRenderMode && f.c.buildErr == nil { p := r.RequestURI if strings.HasSuffix(p, "/") || strings.HasSuffix(p, "html") || strings.HasSuffix(p, "htm") { + if !f.c.visitedURLs.Contains(p) { + // If not already on stack, re-render that single page. + if err := f.c.partialReRender(p); err != nil { + f.c.handleBuildErr(err, fmt.Sprintf("Failed to render %q", p)) + if f.c.showErrorInBrowser { + http.Redirect(w, r, p, 301) + return + } + } + } + f.c.visitedURLs.Add(p) + } } h.ServeHTTP(w, r) |