@@ -22,6 +22,7 @@ import (
2222 "net/url"
2323 "os"
2424 "path/filepath"
25+ "sort"
2526 "strconv"
2627 "strings"
2728 "sync"
@@ -118,12 +119,42 @@ type Site struct {
118119 outputFormatsConfig output.Formats
119120 mediaTypesConfig media.Types
120121
122+ // We render each site for all the relevant output formats in serial with
123+ // this rendering context pointing to the current one.
124+ rc * siteRenderingContext
125+
126+ // The output formats that we need to render this site in. This slice
127+ // will be fixed once set.
128+ // This will be the union of Site.Pages' outputFormats.
129+ // This slice will be sorted.
130+ renderFormats output.Formats
131+
121132 // Logger etc.
122133 * deps.Deps `json:"-"`
123134
124135 siteStats * siteStats
125136}
126137
138+ type siteRenderingContext struct {
139+ output.Format
140+ }
141+
142+ func (s * Site ) initRenderFormats () {
143+ formatSet := make (map [string ]bool )
144+ formats := output.Formats {}
145+ for _ , p := range s .Pages {
146+ for _ , f := range p .outputFormats {
147+ if ! formatSet [f .Name ] {
148+ formats = append (formats , f )
149+ formatSet [f .Name ] = true
150+ }
151+ }
152+ }
153+
154+ sort .Sort (formats )
155+ s .renderFormats = formats
156+ }
157+
127158type siteStats struct {
128159 pageCount int
129160 pageCountRegular int
@@ -971,8 +1002,13 @@ func (s *Site) render() (err error) {
9711002 }
9721003 s .timerStep ("render and write aliases" )
9731004
974- if err = s .renderPages (); err != nil {
975- return
1005+ // TODO(bep) render consider this, ref. render404 etc.
1006+ s .initRenderFormats ()
1007+ for _ , rf := range s .renderFormats {
1008+ s .rc = & siteRenderingContext {Format : rf }
1009+ if err = s .renderPages (); err != nil {
1010+ return
1011+ }
9761012 }
9771013 s .timerStep ("render and write pages" )
9781014
0 commit comments