From d712d6f3310121b80fa00398af01b4d200e391a0 Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Wed, 2 Oct 2013 17:25:16 -0400 Subject: Moving transformation on a per-page level --- hugolib/site.go | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'hugolib') diff --git a/hugolib/site.go b/hugolib/site.go index dd069a28a..358a00edf 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -539,7 +539,6 @@ func (s *Site) NewNode() *Node { } func (s *Site) render(d interface{}, out string, layouts ...string) (err error) { - reader, writer := io.Pipe() layout := s.findFirstLayout(layouts...) if layout == "" { @@ -548,14 +547,35 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error) } return } + + section := "" + page, ok := d.(*Page) + if ok { + section = page.Section + } + + fmt.Println("Section is:", section) + + transformer := transform.NewChain( + &transform.AbsURL{BaseURL: s.Config.BaseUrl}, + &transform.NavActive{Section: section}, + ) + + renderReader, renderWriter := io.Pipe() go func() { - err = s.renderThing(d, layout, writer) + err = s.renderThing(d, layout, renderWriter) if err != nil { panic(err) } }() - return s.WritePublic(out, reader) + trReader, trWriter := io.Pipe() + go func() { + transformer.Apply(trWriter, renderReader) + trWriter.Close() + }() + + return s.WritePublic(out, trReader) } func (s *Site) findFirstLayout(layouts ...string) (layout string) { @@ -590,24 +610,12 @@ func (s *Site) initTarget() { } } -func (s *Site) WritePublic(path string, content io.Reader) (err error) { +func (s *Site) WritePublic(path string, reader io.Reader) (err error) { s.initTarget() if s.Config.Verbose { fmt.Println(path) } - - if s.Transformer == nil { - s.Transformer = transform.NewChain( - &transform.AbsURL{BaseURL: s.Config.BaseUrl}, - &transform.NavActive{Section: "tbd"}, - ) - } - reader, writer := io.Pipe() - go func() { - s.Transformer.Apply(writer, content) - writer.Close() - }() return s.Target.Publish(path, reader) } -- cgit v1.2.3