diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-05 10:24:37 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-13 22:44:15 +0300 |
commit | 2bcbf104006e0ec03be4fd500f2519301d460f8c (patch) | |
tree | c0a9f17515d1d8789efc47aa8bc790e111a9c5d0 /hugolib | |
parent | 1e4d082cf5b92fedbc60b1b4f0e9d1ee6ec45e33 (diff) |
hugolib: Prepare render per output format
See #3220
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/hugo_sites.go | 8 | ||||
-rw-r--r-- | hugolib/hugo_sites_build.go | 27 | ||||
-rw-r--r-- | hugolib/shortcode.go | 5 | ||||
-rw-r--r-- | hugolib/site.go | 38 |
4 files changed, 47 insertions, 31 deletions
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go index b18e66bac..8a8fc2223 100644 --- a/hugolib/hugo_sites.go +++ b/hugolib/hugo_sites.go @@ -492,7 +492,13 @@ func (h *HugoSites) setupTranslations() { } } -func (s *Site) preparePagesForRender(cfg *BuildCfg) { +func (s *Site) preparePagesForRender(outFormatIdx int, cfg *BuildCfg) { + + if outFormatIdx > 0 { + // TODO(bep) for now + return + } + pageChan := make(chan *Page) wg := &sync.WaitGroup{} numWorkers := getGoMaxProcs() * 4 diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go index 58088fd7c..12689f6de 100644 --- a/hugolib/hugo_sites_build.go +++ b/hugolib/hugo_sites_build.go @@ -203,26 +203,31 @@ func (h *HugoSites) assemble(config *BuildCfg) error { return err } - for _, s := range h.Sites { - s.preparePagesForRender(config) - } - return nil } func (h *HugoSites) render(config *BuildCfg) error { - if !config.SkipRender { - for _, s := range h.Sites { - if err := s.render(); err != nil { - return err - } - if config.PrintStats { - s.Stats() + for _, s := range h.Sites { + s.initRenderFormats() + for i, rf := range s.renderFormats { + s.rc = &siteRenderingContext{Format: rf} + s.preparePagesForRender(i, config) + + if !config.SkipRender { + if err := s.render(i); err != nil { + return err + } } } + if !config.SkipRender && config.PrintStats { + s.Stats() + } + } + + if !config.SkipRender { if err := h.renderCrossSitesArtifacts(); err != nil { return err } diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index b088ed61d..abe445d71 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -309,6 +309,7 @@ func executeShortcodeFuncMap(funcs map[string]func() (string, error)) (map[strin } func renderShortcodes(shortcodes map[string]shortcode, p *Page) map[string]func() (string, error) { + renderedShortcodes := make(map[string]func() (string, error)) for key, sc := range shortcodes { @@ -316,8 +317,8 @@ func renderShortcodes(shortcodes map[string]shortcode, p *Page) map[string]func( // need to have something to replace with renderedShortcodes[key] = emptyShortcodeFn } else { - shorctode := sc - renderedShortcodes[key] = func() (string, error) { return renderShortcode(shorctode, nil, p), nil } + shortcode := sc + renderedShortcodes[key] = func() (string, error) { return renderShortcode(shortcode, nil, p), nil } } } diff --git a/hugolib/site.go b/hugolib/site.go index 9bd9b4923..bd029d47a 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -986,31 +986,35 @@ func (s *Site) setupSitePages() { s.Info.LastChange = siteLastChange } -func (s *Site) render() (err error) { +func (s *Site) render(outFormatIdx int) (err error) { + + if outFormatIdx == 0 { + if err = s.preparePages(); err != nil { + return + } + s.timerStep("prepare pages") + + // Aliases must be rendered before pages. + // Some sites, Hugo docs included, have faulty alias definitions that point + // to itself or another real page. These will be overwritten in the next + // step. + if err = s.renderAliases(); err != nil { + return + } + s.timerStep("render and write aliases") - if err = s.preparePages(); err != nil { - return } - s.timerStep("prepare pages") - // Aliases must be rendered before pages. - // Some sites, Hugo docs included, have faulty alias definitions that point - // to itself or another real page. These will be overwritten in the next - // step. - if err = s.renderAliases(); err != nil { + if err = s.renderPages(); err != nil { return } - s.timerStep("render and write aliases") + + s.timerStep("render and write pages") // TODO(bep) render consider this, ref. render404 etc. - s.initRenderFormats() - for _, rf := range s.renderFormats { - s.rc = &siteRenderingContext{Format: rf} - if err = s.renderPages(); err != nil { - return - } + if outFormatIdx > 0 { + return } - s.timerStep("render and write pages") if err = s.renderSitemap(); err != nil { return |