mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-12-18 03:27:35 +00:00
Fix atom feed generation
This commit is contained in:
parent
c9bf66a967
commit
87c65818be
33
dir.go
33
dir.go
|
@ -12,13 +12,13 @@ import (
|
||||||
|
|
||||||
// Dir represents a directory.
|
// Dir represents a directory.
|
||||||
type Dir struct {
|
type Dir struct {
|
||||||
Title string // Directory title.
|
Title string // Directory title.
|
||||||
Content string // Directory index content.
|
Content string // Directory index content.
|
||||||
Path string // Directory path.
|
Path string // Directory path.
|
||||||
Pages []*Page // Pages in this directory.
|
Pages []*Page // Pages in this directory.
|
||||||
Dirs []*Dir // Subdirectories.
|
Dirs []*Dir // Subdirectories.
|
||||||
index *Page // The index page.
|
index *Page // The index page.
|
||||||
feeds map[string][]byte // Feeds.
|
feed []byte // Atom feed.
|
||||||
|
|
||||||
inputExt string // input file extension
|
inputExt string // input file extension
|
||||||
outputExt string // output file extension
|
outputExt string // output file extension
|
||||||
|
@ -33,8 +33,7 @@ func NewDir(path string) *Dir {
|
||||||
path = "/" + path + "/"
|
path = "/" + path + "/"
|
||||||
}
|
}
|
||||||
return &Dir{
|
return &Dir{
|
||||||
Path: path,
|
Path: path,
|
||||||
feeds: map[string][]byte{},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ func (d *Dir) manipulate(cfg *Config) error {
|
||||||
if err := tmpl.Execute(&b, feed); err != nil {
|
if err := tmpl.Execute(&b, feed); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
d.feeds[pathpkg.Join(d.Path, "atom.xml")] = b.Bytes()
|
d.feed = b.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manipulate subdirectories
|
// 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
|
// Write subdirectories
|
||||||
for _, dir := range d.Dirs {
|
for _, dir := range d.Dirs {
|
||||||
dir.write(dstDir, format)
|
dir.write(dstDir, format)
|
||||||
|
|
Loading…
Reference in a new issue