hugolib: Init the content and shortcodes early - hugo - [fork] hugo port for 9front
HTML git clone git@git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit 19084eaf74246feac61d618c55031369520dfa8e
DIR parent 47e7788b3c30de6fb895522096baf2c13598c317
HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date: Sun, 22 Apr 2018 11:18:39 +0200
hugolib: Init the content and shortcodes early
In most cases we could delay the content init until rendering time, but there could be use cases where the templates would depend on state set in the shortcodes (.Page.Scratch.Set), so we need to do this early.
See #4632
Diffstat:
M hugolib/hugo_sites.go | 38 +++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 10 deletions(-)
---
DIR diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
@@ -560,22 +560,40 @@ func (h *HugoSites) setupTranslations() {
}
func (s *Site) preparePagesForRender(cfg *BuildCfg) {
+
+ pageChan := make(chan *Page)
+ wg := &sync.WaitGroup{}
+
+ numWorkers := getGoMaxProcs() * 4
+
+ for i := 0; i < numWorkers; i++ {
+ wg.Add(1)
+ go func(pages <-chan *Page, wg *sync.WaitGroup) {
+ defer wg.Done()
+ for p := range pages {
+ p.setContentInit(cfg)
+
+ // In most cases we could delay the content init until rendering time,
+ // but there could be use cases where the templates would depend
+ // on state set in the shortcodes (.Page.Scratch.Set), so we
+ // need to do this early. This will do the needed recursion.
+ p.initContent()
+ }
+ }(pageChan, wg)
+ }
+
for _, p := range s.Pages {
- p.setContentInit(cfg)
- // The skip render flag is used in many tests. To make sure that they
- // have access to the content, we need to manually initialize it here.
- if cfg.SkipRender {
- p.initContent()
- }
+ pageChan <- p
}
for _, p := range s.headlessPages {
- p.setContentInit(cfg)
- if cfg.SkipRender {
- p.initContent()
- }
+ pageChan <- p
}
+ close(pageChan)
+
+ wg.Wait()
+
}
// Pages returns all pages for all sites.