small pixel drawing of a pufferfish j3s.sh

feed/feed.go

package feed

import (
	"log"
	"sort"

	"github.com/SlyMarbo/rss"
)

var lovelyFeedList = []string{
	"https://100r.co/links/rss.xml",
	"https://begriffs.com/atom.xml",
	"https://reese.ovine.xyz/feed.rss",
	"https://davebucklin.com/feed.xml",
	"https://facklambda.dev/atom.xml",
	"https://icyphox.sh/blog/feed.xml",
	"https://katherine.cox-buday.com/rss.xml",
	"https://kattraxler.github.io/feed.xml",
	"https://sanine.net/rss.xml",
	"https://sequentialread.com/rss",
	"https://spencerkrum.com/index.xml",
}

func GetAllFeeds() []rss.Feed {
	var feeds []rss.Feed
	for _, f := range lovelyFeedList {
		feed, err := rss.Fetch(f)
		if err != nil {
			log.Println(err)
			continue
		}
		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
}