1
0
Fork 0
mirror of https://github.com/vbatts/sl-feeds.git synced 2024-11-22 15:55:39 +00:00
sl-feeds/changelog/feeds.go
Vincent Batts 1cca828855
feeds: report updates differently
If there are "0 updates" then don't report as such.

Found as http://bear.alienbase.nl/mirrors//alien-kde/ChangeLog.txt
updates don't match the same regex as slackware update entries, so it
reported 0 updates. This is a TODO to improve that regex.

Reported-by: alienBob
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-02-22 12:11:55 -05:00

55 lines
1.3 KiB
Go

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},
Description: "generated by github.com/vbatts/sl-feeds",
Created: oldestEntryTime,
Updated: newestEntryTime,
}
feed.Items = make([]*feeds.Item, len(entries))
for i, e := range entries {
url := fmt.Sprintf("%s/ChangeLog.txt#src=feeds&time=%d", link, e.Date.Unix())
feed.Items[i] = &feeds.Item{
Created: e.Date,
Link: &feeds.Link{Href: url},
Description: e.ToHTML(),
Id: url,
}
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)
} else if len(e.Updates) == 0 {
feed.Items[i].Title = ""
} else {
feed.Items[i].Title = fmt.Sprintf("%d %s", len(e.Updates), updateWord)
}
}
return feed, nil
}