mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Externalize the writing of content to a target
Introducing the target module in hugo. This provides the simple interface for writing content given a label (filename) and a io.Reader containing the content to be written. If site.Target is not set, it defaults back to the original behavior of writing to file system. In hugolib/site_url_test.go I have an InMemoryTarget for testing purposes and use it to see if the final output of a render matches.
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/spf13/hugo/target"
|
||||
"github.com/spf13/nitro"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
@@ -40,6 +41,7 @@ type Site struct {
|
||||
Info SiteInfo
|
||||
Shortcodes map[string]ShortcodeFunc
|
||||
timer *nitro.B
|
||||
Target target.Publisher
|
||||
}
|
||||
|
||||
type SiteInfo struct {
|
||||
@@ -628,7 +630,7 @@ func (s *Site) NewNode() Node {
|
||||
|
||||
func (s *Site) RenderThing(d interface{}, layout string) (*bytes.Buffer, error) {
|
||||
if s.Tmpl.Lookup(layout) == nil {
|
||||
return nil, errors.New("Layout not found")
|
||||
return nil, errors.New(fmt.Sprintf("Layout not found: %s", layout))
|
||||
}
|
||||
buffer := new(bytes.Buffer)
|
||||
err := s.Tmpl.ExecuteTemplate(buffer, layout, d)
|
||||
@@ -654,6 +656,10 @@ func (s *Site) NewXMLBuffer() *bytes.Buffer {
|
||||
|
||||
func (s *Site) WritePublic(path string, content []byte) {
|
||||
|
||||
if s.Target != nil {
|
||||
s.Target.Publish(path, bytes.NewReader(content))
|
||||
}
|
||||
|
||||
if s.Config.Verbose {
|
||||
fmt.Println(path)
|
||||
}
|
||||
|
Reference in New Issue
Block a user