diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-04-28 09:40:50 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-13 22:44:15 +0300 |
commit | 1e4d082cf5b92fedbc60b1b4f0e9d1ee6ec45e33 (patch) | |
tree | ceedf3ca1d214839a587ea85340673c7b38f9ac2 /hugolib | |
parent | 1d70aa9826776e7c38a72864565daeb34a55ca52 (diff) |
hubolib: Refactor site rendering with an "output format context"
Fixes #3397
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/site.go | 40 | ||||
-rw-r--r-- | hugolib/site_render.go | 5 |
2 files changed, 43 insertions, 2 deletions
diff --git a/hugolib/site.go b/hugolib/site.go index 4f7c2c5fb..9bd9b4923 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -22,6 +22,7 @@ import ( "net/url" "os" "path/filepath" + "sort" "strconv" "strings" "sync" @@ -118,12 +119,42 @@ type Site struct { outputFormatsConfig output.Formats mediaTypesConfig media.Types + // We render each site for all the relevant output formats in serial with + // this rendering context pointing to the current one. + rc *siteRenderingContext + + // The output formats that we need to render this site in. This slice + // will be fixed once set. + // This will be the union of Site.Pages' outputFormats. + // This slice will be sorted. + renderFormats output.Formats + // Logger etc. *deps.Deps `json:"-"` siteStats *siteStats } +type siteRenderingContext struct { + output.Format +} + +func (s *Site) initRenderFormats() { + formatSet := make(map[string]bool) + formats := output.Formats{} + for _, p := range s.Pages { + for _, f := range p.outputFormats { + if !formatSet[f.Name] { + formats = append(formats, f) + formatSet[f.Name] = true + } + } + } + + sort.Sort(formats) + s.renderFormats = formats +} + type siteStats struct { pageCount int pageCountRegular int @@ -971,8 +1002,13 @@ func (s *Site) render() (err error) { } s.timerStep("render and write aliases") - if err = s.renderPages(); err != nil { - return + // 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 + } } s.timerStep("render and write pages") diff --git a/hugolib/site_render.go b/hugolib/site_render.go index 6aeaf677a..ac7b25da7 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -81,6 +81,11 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa pageOutput, err = page.mainPageOutput.copyWithFormat(outFormat) } + if outFormat != page.s.rc.Format { + // Will be rendered ... later. + continue + } + if err != nil { s.Log.ERROR.Printf("Failed to create output page for type %q for page %q: %s", outFormat.Name, page, err) continue |