From 80b314ffb7ea323ddc90ea40833f6cda1b46027b Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Tue, 20 Apr 2021 14:49:45 -0400 Subject: [PATCH] Fix atom feed generation --- dir.go | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/dir.go b/dir.go index 7e5f2ed..ad00772 100644 --- a/dir.go +++ b/dir.go @@ -12,13 +12,13 @@ import ( // Dir represents a directory. type Dir struct { - Title string // Directory title. - Content string // Directory index content. - Path string // Directory path. - Pages []*Page // Pages in this directory. - Dirs []*Dir // Subdirectories. - index *Page // The index page. - feeds map[string][]byte // Feeds. + Title string // Directory title. + Content string // Directory index content. + Path string // Directory path. + Pages []*Page // Pages in this directory. + Dirs []*Dir // Subdirectories. + index *Page // The index page. + feed []byte // Atom feed. inputExt string // input file extension outputExt string // output file extension @@ -33,8 +33,7 @@ func NewDir(path string) *Dir { path = "/" + path + "/" } return &Dir{ - Path: path, - feeds: map[string][]byte{}, + Path: path, } } @@ -127,7 +126,7 @@ func (d *Dir) manipulate(cfg *Config) error { if err := tmpl.Execute(&b, feed); err != nil { return err } - d.feeds[pathpkg.Join(d.Path, "atom.xml")] = b.Bytes() + d.feed = b.Bytes() } // Manipulate subdirectories @@ -182,6 +181,20 @@ func (d *Dir) write(dstDir string, format Format) error { } } + // Write the atom feed + if d.feed != nil { + const path = "atom.xml" + dstPath := pathpkg.Join(dstDir, path) + os.MkdirAll(dstDir, 0755) + f, err := os.Create(dstPath) + if err != nil { + return err + } + if _, err := f.Write(d.feed); err != nil { + return err + } + } + // Write subdirectories for _, dir := range d.Dirs { dir.write(dstDir, format)