mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 22:51:32 -05:00
Buffers instead of pipes
This commit is contained in:
parent
226bc8f59f
commit
1fbcaf9279
1 changed files with 37 additions and 36 deletions
|
@ -31,6 +31,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ = transform.AbsURL
|
||||||
|
|
||||||
var DefaultTimer *nitro.B
|
var DefaultTimer *nitro.B
|
||||||
|
|
||||||
func MakePermalink(base *url.URL, path *url.URL) *url.URL {
|
func MakePermalink(base *url.URL, path *url.URL) *url.URL {
|
||||||
|
@ -167,7 +169,6 @@ func (s *Site) Render() (err error) {
|
||||||
s.timerStep("render and write aliases")
|
s.timerStep("render and write aliases")
|
||||||
s.ProcessShortcodes()
|
s.ProcessShortcodes()
|
||||||
s.timerStep("render shortcodes")
|
s.timerStep("render shortcodes")
|
||||||
s.timerStep("absolute URLify")
|
|
||||||
if err = s.RenderIndexes(); err != nil {
|
if err = s.RenderIndexes(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -580,19 +581,24 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error)
|
||||||
section, _ = page.RelPermalink()
|
section, _ = page.RelPermalink()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
absURL, err := transform.AbsURL(s.Config.BaseUrl)
|
absURL, err := transform.AbsURL(s.Config.BaseUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
transformer := transform.NewChain(
|
transformer := transform.NewChain(
|
||||||
append(absURL, transform.NavActive(section, "hugo-nav")...)...
|
append(absURL, transform.NavActive(section, "hugo-nav")...)...,
|
||||||
)
|
)
|
||||||
|
|
||||||
renderReader, renderWriter := io.Pipe()
|
var RenderBuffer *bytes.Buffer
|
||||||
go func() {
|
|
||||||
err = s.renderThing(d, layout, renderWriter)
|
if strings.HasSuffix(out, ".xml") {
|
||||||
|
RenderBuffer = s.NewXMLBuffer()
|
||||||
|
} else {
|
||||||
|
RenderBuffer = new(bytes.Buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.renderThing(d, layout, RenderBuffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Behavior here should be dependent on if running in server or watch mode.
|
// Behavior here should be dependent on if running in server or watch mode.
|
||||||
fmt.Println(fmt.Errorf("Rendering error: %v", err))
|
fmt.Println(fmt.Errorf("Rendering error: %v", err))
|
||||||
|
@ -600,15 +606,10 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
|
||||||
trReader, trWriter := io.Pipe()
|
var outBuffer = new(bytes.Buffer)
|
||||||
go func() {
|
transformer.Apply(outBuffer, RenderBuffer)
|
||||||
transformer.Apply(trWriter, renderReader)
|
return s.WritePublic(out, outBuffer)
|
||||||
trWriter.Close()
|
|
||||||
}()
|
|
||||||
|
|
||||||
return s.WritePublic(out, trReader)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) findFirstLayout(layouts ...string) (layout string) {
|
func (s *Site) findFirstLayout(layouts ...string) (layout string) {
|
||||||
|
@ -620,16 +621,16 @@ func (s *Site) findFirstLayout(layouts ...string) (layout string) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) renderThing(d interface{}, layout string, w io.WriteCloser) error {
|
func (s *Site) renderThing(d interface{}, layout string, w io.Writer) error {
|
||||||
// If the template doesn't exist, then return, but leave the Writer open
|
// If the template doesn't exist, then return, but leave the Writer open
|
||||||
if s.Tmpl.Lookup(layout) == nil {
|
if s.Tmpl.Lookup(layout) == nil {
|
||||||
return fmt.Errorf("Layout not found: %s", layout)
|
return fmt.Errorf("Layout not found: %s", layout)
|
||||||
}
|
}
|
||||||
defer w.Close()
|
//defer w.Close()
|
||||||
return s.Tmpl.ExecuteTemplate(w, layout, d)
|
return s.Tmpl.ExecuteTemplate(w, layout, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) whyNewXMLBuffer() *bytes.Buffer {
|
func (s *Site) NewXMLBuffer() *bytes.Buffer {
|
||||||
header := "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n"
|
header := "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n"
|
||||||
return bytes.NewBufferString(header)
|
return bytes.NewBufferString(header)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue