Return an error with WritePublic

This commit is contained in:
Noah Campbell 2013-08-30 21:24:25 -07:00
parent 097b782a80
commit 0fdea0c2c2

View file

@ -439,7 +439,10 @@ func (s *Site) RenderAliases() error {
if err != nil {
return err
}
s.WritePublic(a, content.Bytes())
err = s.WritePublic(a, content.Bytes())
if err != nil {
return err
}
}
}
return nil
@ -456,10 +459,14 @@ func (s *Site) RenderPages() error {
return nil
}
func (s *Site) WritePages() {
func (s *Site) WritePages() (err error) {
for _, p := range s.Pages {
s.WritePublic(p.OutFile, p.RenderedContent.Bytes())
err = s.WritePublic(p.OutFile, p.RenderedContent.Bytes())
if err != nil {
return
}
}
return
}
func (s *Site) RenderIndexes() error {
@ -493,7 +500,10 @@ func (s *Site) RenderIndexes() error {
base = plural + "/" + k + "/" + "index"
}
s.WritePublic(base+".html", x.Bytes())
err = s.WritePublic(base+".html", x.Bytes())
if err != nil {
return err
}
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
// XML Feed
@ -505,7 +515,10 @@ func (s *Site) RenderIndexes() error {
}
n.Permalink = template.HTML(string(n.Site.BaseUrl) + n.Url)
s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
s.WritePublic(base+".xml", y.Bytes())
err = s.WritePublic(base+".xml", y.Bytes())
if err != nil {
return err
}
}
}
}
@ -527,8 +540,14 @@ func (s *Site) RenderIndexesIndexes() (err error) {
n.Data["OrderedIndex"] = s.Info.Indexes[plural]
x, err := s.RenderThing(n, layout)
s.WritePublic(plural+"/index.html", x.Bytes())
return err
if err != nil {
return err
}
err = s.WritePublic(plural+"/index.html", x.Bytes())
if err != nil {
return err
}
}
}
return
@ -549,7 +568,10 @@ func (s *Site) RenderLists() error {
if err != nil {
return err
}
s.WritePublic(section+"/index.html", content.Bytes())
err = s.WritePublic(section+"/index.html", content.Bytes())
if err != nil {
return err
}
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
// XML Feed
@ -561,7 +583,8 @@ func (s *Site) RenderLists() error {
n.Permalink = template.HTML(string(n.Site.BaseUrl) + n.Url)
y := s.NewXMLBuffer()
s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
s.WritePublic(section+"/index.xml", y.Bytes())
err = s.WritePublic(section+"/index.xml", y.Bytes())
return err
}
}
return nil
@ -585,7 +608,10 @@ func (s *Site) RenderHomePage() error {
if err != nil {
return err
}
s.WritePublic("index.html", x.Bytes())
err = s.WritePublic("index.html", x.Bytes())
if err != nil {
return err
}
if a := s.Tmpl.Lookup("rss.xml"); a != nil {
// XML Feed
@ -594,7 +620,8 @@ func (s *Site) RenderHomePage() error {
n.Permalink = template.HTML(string(n.Site.BaseUrl) + "index.xml")
y := s.NewXMLBuffer()
s.Tmpl.ExecuteTemplate(y, "rss.xml", n)
s.WritePublic("index.xml", y.Bytes())
err = s.WritePublic("index.xml", y.Bytes())
return err
}
if a := s.Tmpl.Lookup("404.html"); a != nil {
@ -605,7 +632,8 @@ func (s *Site) RenderHomePage() error {
if err != nil {
return err
}
s.WritePublic("404.html", x.Bytes())
err = s.WritePublic("404.html", x.Bytes())
return err
}
return nil
@ -652,10 +680,10 @@ func (s *Site) NewXMLBuffer() *bytes.Buffer {
return bytes.NewBufferString(header)
}
func (s *Site) WritePublic(path string, content []byte) {
func (s *Site) WritePublic(path string, content []byte) (err error) {
if s.Target != nil {
s.Target.Publish(path, bytes.NewReader(content))
return s.Target.Publish(path, bytes.NewReader(content))
}
if s.Config.Verbose {
@ -665,14 +693,14 @@ func (s *Site) WritePublic(path string, content []byte) {
path, filename := filepath.Split(path)
path = filepath.FromSlash(s.Config.GetAbsPath(filepath.Join(s.Config.PublishDir, path)))
err := mkdirIf(path)
err = mkdirIf(path)
if err != nil {
fmt.Println(err)
return
}
file, _ := os.Create(filepath.Join(path, filename))
defer file.Close()
file.Write(content)
_, err = file.Write(content)
return
}