aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib
diff options
context:
space:
mode:
authorNoah Campbell <[email protected]>2013-10-02 17:25:16 -0400
committerNoah Campbell <[email protected]>2013-10-08 18:42:03 +0200
commitd712d6f3310121b80fa00398af01b4d200e391a0 (patch)
treeb9e3e3796ced710d52e84de4d152ea0d7f0bac24 /hugolib
parent9032a228b01906eea7ad92269c5bad109c333418 (diff)
downloadhugo-d712d6f3310121b80fa00398af01b4d200e391a0.tar.gz
hugo-d712d6f3310121b80fa00398af01b4d200e391a0.zip
Moving transformation on a per-page level
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/site.go40
1 files changed, 24 insertions, 16 deletions
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)
}