fix FeedSource item sorting

we were sorting by strings instead of parsed dates and it was getting
confused by RFC1123 dates that looked like

    Thu, 02 Dec 2021 00:00:00 -0700
    Mon, 20 Sep 2021 00:00:00 -0600
    Mon, 06 Sep 2021 00:00:00 -0600
    Thu, 02 Sep 2021 00:00:00 -0600
    Sun, 22 Aug 2021 00:00:00 -0600

which of course sort like

    Thu, 02 Sep 2021 00:00:00 -0600
    Thu, 02 Dec 2021 00:00:00 -0700
    Sun, 22 Aug 2021 00:00:00 -0600
    Mon, 20 Sep 2021 00:00:00 -0600
    Mon, 06 Sep 2021 00:00:00 -0600
master
magical 2022-01-01 00:52:31 +00:00
parent 2f3ae0c09b
commit ad7a1edaf1
1 changed files with 14 additions and 2 deletions

16
main.go
View File

@ -146,8 +146,20 @@ func (src *FeedSource) update(ctx context.Context) {
}
items := feed.Items
sort.Slice(items, func(i, j int) bool {
return items[i].Updated >= items[j].Updated
sort.SliceStable(items, func(i, j int) bool {
var d1, d2 time.Time
if items[i].PublishedParsed != nil {
d1 = *items[i].PublishedParsed
} else if items[i].UpdatedParsed != nil {
d1 = *items[i].UpdatedParsed
}
if items[j].PublishedParsed != nil {
d2 = *items[j].PublishedParsed
} else if items[j].UpdatedParsed != nil {
d2 = *items[j].UpdatedParsed
}
return !d1.Before(d2)
})
src.Title = feed.Title
src.Items = items