small pixel drawing of a pufferfish j3s.sh

Move feed sort to feed package
Jes Olson j3s@c3f.net
Mon, 18 Jul 2022 02:29:02 -0500
commit

2a41207e2fd9b4cc1634d6e9b8944c363e62f1c6

parent

fc1eaf43391ab4dd4bc631172accef246cfa4567

2 files changed, 18 insertions(+), 13 deletions(-)

jump to
M feed/feed.gofeed/feed.go

@@ -2,6 +2,8 @@ package feed

import ( "log" + "sort" + "github.com/SlyMarbo/rss" )

@@ -51,3 +53,18 @@ feeds = append(feeds, *feed)

} return feeds } + +func SortItems(f []rss.Feed) []rss.Item { + var posts []rss.Item + for _, f := range f { + for _, i := range f.Items { + posts = append(posts, *i) + } + } + + // magick slice sorter by date + sort.Slice(posts, func(i, j int) bool { + return posts[i].Date.After(posts[j].Date) + }) + return posts +}
M main.gomain.go

@@ -10,7 +10,6 @@ "math/rand"

"net/http" "os" "path/filepath" - "sort" "strings" "time"

@@ -237,19 +236,8 @@ <body>

<table> <tbody>`) - var posts []rss.Item - for _, f := range data.Feeds { - for _, i := range f.Items { - posts = append(posts, *i) - } - } - - // magick slice sorter by date - sort.Slice(posts, func(i, j int) bool { - return posts[i].Date.After(posts[j].Date) - }) - // printf the shit + posts := feed.SortItems(data.Feeds) for _, p := range posts { fmt.Fprintf(w, "<tr><td>") fmt.Fprintf(w, `<a href="%s">%s</a>`, p.Link, p.Title)