From 94e736c5e167a0ee70a528e1c19d64a47e7929c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 30 Jan 2018 10:33:57 +0100 Subject: [PATCH] hugolib: Extract the Fast Render Mode logic into a method This also improves on the previous commit as it takes pages without content files into account. Closes #4339 --- hugolib/hugo_sites.go | 20 ++++++++++++++++++++ hugolib/site.go | 2 +- hugolib/site_render.go | 9 +++------ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go index c52aec8133c..e6000e06dd0 100644 --- a/hugolib/hugo_sites.go +++ b/hugolib/hugo_sites.go @@ -325,6 +325,26 @@ type BuildCfg struct { RecentlyVisited map[string]bool } +// shouldRender is used in the Fast Render Mode to determine if we need to re-render +// a Page: If it is recently visited (the home pages will always be in this set) or changed. +// Note that a page does not have to have a content page / file. +// For regular builds, this will allways return true. +func (cfg *BuildCfg) shouldRender(p *Page) bool { + if len(cfg.RecentlyVisited) == 0 { + return true + } + + if cfg.RecentlyVisited[p.RelPermalink()] { + return true + } + + if cfg.whatChanged != nil && p.File != nil && cfg.whatChanged.files[p.File.Filename()] { + return true + } + + return false +} + func (h *HugoSites) renderCrossSitesArtifacts() error { if !h.multilingual.enabled() || h.IsMultihost() { diff --git a/hugolib/site.go b/hugolib/site.go index 8a3cde9c7ce..0e5f034a463 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -941,7 +941,7 @@ func (s *Site) render(config *BuildCfg, outFormatIdx int) (err error) { } - if err = s.renderPages(config.RecentlyVisited, config.whatChanged.files); err != nil { + if err = s.renderPages(config); err != nil { return } diff --git a/hugolib/site_render.go b/hugolib/site_render.go index eebaec4fae9..a2031e0c070 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -24,7 +24,7 @@ import ( // renderPages renders pages each corresponding to a markdown file. // TODO(bep np doc -func (s *Site) renderPages(filter map[string]bool, files map[string]bool) error { +func (s *Site) renderPages(cfg *BuildCfg) error { results := make(chan error) pages := make(chan *Page) @@ -47,13 +47,10 @@ func (s *Site) renderPages(filter map[string]bool, files map[string]bool) error } - hasFilter := filter != nil && len(filter) > 0 - for _, page := range s.Pages { - if hasFilter && !filter[page.RelPermalink()] && !files[page.Source.Filename()] { - continue + if cfg.shouldRender(page) { + pages <- page } - pages <- page } close(pages)