summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-10-14 13:40:43 +0200
committerGitHub <noreply@github.com>2017-10-14 13:40:43 +0200
commit60bd332c1f68e49e6ac439047e7c660865189380 (patch)
tree49274b7ce5ff73e0f51d6ac9e20740e6e3765f04 /hugolib
parent6a30874f19610a38e846e120aac03c68e12f9b7b (diff)
Only re-render the view(s) you're working on
Hugo already, in its server mode, support partial rebuilds. To put it simply: If you change `about.md`, only that content page is read and processed, then Hugo does some processing (taxonomies etc.) and the full site is rendered. This commit covers the rendering part: We now only re-render the pages you work on, i.e. the last n pages you watched in the browser (which obviously also includes the page in the example above). To be more specific: When you are running the hugo server in watch (aka. livereload) mode, and change a template or a content file, then we do a partial re-rendering of the following: * The current content page (if it is a content change) * The home page * Up to the last 10 pages you visited on the site. This should in most cases be enough, but if you navigate to something completely different, you may see stale content. Doing an edit will then refresh that page. Note that this feature is enabled by default. To turn it off, run `hugo server --disableFastRender`. Fixes #3962 See #1643
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/config.go1
-rw-r--r--hugolib/hugo_sites.go2
-rw-r--r--hugolib/hugo_sites_build.go2
-rw-r--r--hugolib/site.go4
-rw-r--r--hugolib/site_render.go7
5 files changed, 12 insertions, 4 deletions
diff --git a/hugolib/config.go b/hugolib/config.go
index d0ade018f..acfa0704d 100644
--- a/hugolib/config.go
+++ b/hugolib/config.go
@@ -152,6 +152,7 @@ func loadDefaultSettingsFor(v *viper.Viper) error {
v.SetDefault("ignoreFiles", make([]string, 0))
v.SetDefault("disableAliases", false)
v.SetDefault("debug", false)
+ v.SetDefault("disableFastRender", false)
return nil
}
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index e763588bd..6e2340903 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -280,6 +280,8 @@ type BuildCfg struct {
SkipRender bool
// Use this to indicate what changed (for rebuilds).
whatChanged *whatChanged
+ // Recently visited URLs. This is used for partial re-rendering.
+ RecentlyVisited map[string]bool
}
func (h *HugoSites) renderCrossSitesArtifacts() error {
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index b3e0e8bdc..c0749e388 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -230,7 +230,7 @@ func (h *HugoSites) render(config *BuildCfg) error {
s.preparePagesForRender(config)
if !config.SkipRender {
- if err := s.render(i); err != nil {
+ if err := s.render(config, i); err != nil {
return err
}
}
diff --git a/hugolib/site.go b/hugolib/site.go
index f9430b272..28414c7d4 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -893,7 +893,7 @@ func (s *Site) setupSitePages() {
s.Info.LastChange = siteLastChange
}
-func (s *Site) render(outFormatIdx int) (err error) {
+func (s *Site) render(config *BuildCfg, outFormatIdx int) (err error) {
if outFormatIdx == 0 {
if err = s.preparePages(); err != nil {
@@ -917,7 +917,7 @@ func (s *Site) render(outFormatIdx int) (err error) {
}
- if err = s.renderPages(); err != nil {
+ if err = s.renderPages(config.RecentlyVisited); err != nil {
return
}
diff --git a/hugolib/site_render.go b/hugolib/site_render.go
index 42433a70a..4118f3eef 100644
--- a/hugolib/site_render.go
+++ b/hugolib/site_render.go
@@ -27,7 +27,7 @@ import (
// renderPages renders pages each corresponding to a markdown file.
// TODO(bep np doc
-func (s *Site) renderPages() error {
+func (s *Site) renderPages(filter map[string]bool) error {
results := make(chan error)
pages := make(chan *Page)
@@ -44,7 +44,12 @@ func (s *Site) renderPages() error {
go pageRenderer(s, pages, results, wg)
}
+ hasFilter := filter != nil && len(filter) > 0
+
for _, page := range s.Pages {
+ if hasFilter && !filter[page.RelPermalink()] {
+ continue
+ }
pages <- page
}