-
Notifications
You must be signed in to change notification settings - Fork 2
/
atom.go
49 lines (41 loc) · 1.08 KB
/
atom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package engine
import (
"os"
"path/filepath"
"time"
"github.com/gorilla/feeds"
"github.com/petarov/nenu/config"
)
// SpewAtom generate Atom feed from posts
func SpewAtom(posts []*Post) error {
now := time.Now()
feed := &feeds.Feed{
Title: config.YMLConfig.Site.Title,
Link: &feeds.Link{Href: config.YMLConfig.Site.URL},
Description: config.YMLConfig.Site.Description,
Author: &feeds.Author{Name: config.YMLConfig.Site.Author, Email: ""},
Copyright: config.YMLConfig.Footer.Copyright,
Created: now,
}
for _, p := range posts {
feed.Items = append(feed.Items, &feeds.Item{
Title: p.Title,
//Image: &feeds.Image{Url: p.ImageURL},
Link: &feeds.Link{Href: p.PermalinkURL},
Description: p.Summary,
Author: &feeds.Author{Name: config.YMLConfig.Site.Author, Email: ""},
Created: p.date.UTC(),
})
}
atom, err := feed.ToAtom()
if err != nil {
return err
}
f, err := os.Create(filepath.Join(config.TempPath, "feed-atom.xml"))
if err != nil {
return err
}
defer f.Close()
f.WriteString(atom)
return nil
}