2017-01-26 15:39:06 +00:00
|
|
|
package changelog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gorilla/feeds"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ToFeed produces a github.com/gorilla/feeds.Feed that can be written to Atom or Rss
|
|
|
|
func ToFeed(link string, entries []Entry) (*feeds.Feed, error) {
|
|
|
|
var newestEntryTime time.Time
|
|
|
|
var oldestEntryTime time.Time
|
|
|
|
|
|
|
|
for _, e := range entries {
|
|
|
|
if e.Date.After(newestEntryTime) {
|
|
|
|
newestEntryTime = e.Date
|
|
|
|
}
|
|
|
|
if e.Date.Before(oldestEntryTime) {
|
|
|
|
oldestEntryTime = e.Date
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
feed := &feeds.Feed{
|
|
|
|
Title: "",
|
|
|
|
Link: &feeds.Link{Href: link},
|
2017-02-09 19:15:03 +00:00
|
|
|
Description: "generated by github.com/vbatts/sl-feeds",
|
2017-01-26 15:39:06 +00:00
|
|
|
Created: oldestEntryTime,
|
|
|
|
Updated: newestEntryTime,
|
|
|
|
}
|
|
|
|
feed.Items = make([]*feeds.Item, len(entries))
|
|
|
|
for i, e := range entries {
|
2017-02-09 19:51:26 +00:00
|
|
|
url := fmt.Sprintf("%s/ChangeLog.txt#src=feeds&time=%d", link, e.Date.Unix())
|
2017-01-26 15:39:06 +00:00
|
|
|
feed.Items[i] = &feeds.Item{
|
|
|
|
Created: e.Date,
|
2017-02-09 19:51:26 +00:00
|
|
|
Link: &feeds.Link{Href: url},
|
2017-02-09 19:33:35 +00:00
|
|
|
Description: e.ToHTML(),
|
2017-02-09 19:51:26 +00:00
|
|
|
Id: url,
|
2017-01-26 15:39:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateWord := "updates"
|
|
|
|
if len(e.Updates) == 1 {
|
|
|
|
updateWord = "update"
|
|
|
|
}
|
|
|
|
if e.SecurityFix() {
|
|
|
|
feed.Items[i].Title = fmt.Sprintf("%d %s. Including a %s!", len(e.Updates), updateWord, securityFixStr)
|
2017-02-22 17:11:55 +00:00
|
|
|
} else if len(e.Updates) == 0 {
|
|
|
|
feed.Items[i].Title = ""
|
2017-01-26 15:39:06 +00:00
|
|
|
} else {
|
2017-02-22 17:11:55 +00:00
|
|
|
feed.Items[i].Title = fmt.Sprintf("%d %s", len(e.Updates), updateWord)
|
2017-01-26 15:39:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return feed, nil
|
|
|
|
}
|