small pixel drawing of a pufferfish j3s.sh

Make fetching rss feeds better in every way
Jesse Olson j3s@c3f.net
Fri, 11 Feb 2022 04:42:03 +0000
commit

b5c73f1c80eace3df58108a66929e0b3cf14f232

parent

b7529280cfbbec42a0e2c5a6a5dd3f83f322972b

4 files changed, 26 insertions(+), 20 deletions(-)

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

@@ -48,24 +48,21 @@ }

return f } -func FetchRecentFriendPosts() []string { +func FetchFriendFeeds() []rss.Feed { feeds := GetFeeds() - var bunchOfBlogLinks []string - for _, feed := range feeds.FriendFeeds { + var friendFeeds []rss.Feed + for i, feed := range feeds.FriendFeeds { f, err := rss.Fetch(feed) if err != nil { log.Printf(err.Error()) + continue } - for i, item := range f.Items { - log.Printf("%s\n", item.Title) - bunchOfBlogLinks = append(bunchOfBlogLinks, item.Link) - if i == 0 { - // fetch only the most recent post from each friend - break - } - } + fe := *f + friendFeeds = append(friendFeeds, fe) + // todo: make a sort func for []rss.Feed + log.Printf(string(i)) } - return bunchOfBlogLinks + return friendFeeds }
M go.modgo.mod

@@ -2,4 +2,4 @@ module git.j3s.sh/j3s.sh

go 1.16 -require github.com/SlyMarbo/rss v1.0.1 // indirect +require github.com/SlyMarbo/rss v1.0.1
M main.gomain.go

@@ -9,6 +9,7 @@ "path/filepath"

"strings" "git.j3s.sh/j3s.sh/feed" + "github.com/SlyMarbo/rss" ) // templateData is a mega-struct that gets

@@ -20,7 +21,7 @@ // data for use in templates. it's useful for it to be

// global since it may need to be available in arbitrary // contexts. maybe that sucks. but idfk! type templateData struct { - FriendPosts []string + FriendFeeds []rss.Feed } var data templateData

@@ -28,7 +29,7 @@

// the populate function populates the global "data" variable // with ... data. with which to pass into templates. func (t *templateData) populate() { - t.FriendPosts = feed.FetchRecentFriendPosts() + t.FriendFeeds = feed.FetchFriendFeeds() } func main() {
M templates/index.htmltemplates/index.html

@@ -1,14 +1,22 @@

-{{define "title"}}j3s.sh{{end}} -{{define "body"}} +{{ define "title" }}j3s.sh{{ end }} +{{ define "body" }} <marquee><p><i>new! dynamically generated! smol! website! <3</p></i></marquee> <h4>this site is under heavy construction</h4> <img src="/static/under-construction.gif"> <h4>important quotes</h4> +<p><i>everything i do is stitched with her color</p></i> <p><i>the only way out is through</p></i> +<p><i>everything i do is stitched with her color</p></i> <p><i>fear is the mind-killer</p></i> <p><i>everything i do is stitched with her color</p></i> <h4>recent posts from my friends on the web</h4> -{{ range $post := .FriendPosts }} -<li><a href="{{ $post }}">{{ $post }}</a></li> +{{ range $feed := .FriendFeeds }} +<li><a href="{{ (index .Items 0).Link }}"> + {{ if $feed.Title }} + {{ $feed.Title }}: + {{ else }} + {{ $feed.Description }}: + {{ end }} + {{ (index .Items 0).Title }}</a></li> {{ end }} -{{end}} +{{ end }}