small pixel drawing of a pufferfish j3s.sh

Add updating links to friends blogs based on their feeds :D
Jes Olson j3s@c3f.net
Fri, 04 Feb 2022 08:58:01 -0600
commit

c8f388687c412e9ca804702ac284fdb1047980cb

parent

d71d28552988609522255d2a07d71cc2e3e1dc3c

6 files changed, 111 insertions(+), 5 deletions(-)

jump to
A feed/feed.go

@@ -0,0 +1,71 @@

+package feed + +import ( + "log" + + "github.com/SlyMarbo/rss" +) + +type feeds struct { + FriendFeeds []string + CompanyFeeds []string + RandomFeeds []string +} + +func GetFeeds() feeds { + f := feeds{} + f.FriendFeeds = []string{ + "https://begriffs.com/atom.xml", + "https://davebucklin.com/feed.xml", + "https://www.bitquabit.com/index.xml", + "https://blog.jse.li/index.xml", + "https://spencerkrum.com/index.xml", + "https://www.ryanprior.com/posts/index.xml", + "https://kattraxler.github.io/feed.xml", + "https://coderanger.net/atom.xml", + "https://www.namecoin.org/feed.rss", + "https://sanine.net/rss.xml", + "https://sequentialread.com/rss", + } + f.CompanyFeeds = []string{ + "https://cyberia.club/blog/blog.xml", + "https://blog.tildes.net/all.atom.xml", + "https://matrix.org/blog/feed", + "https://puri.sm/feed", + "https://sourcehut.org/blog/index.xml", + "https://frame.work/blog.rss", + } + f.RandomFeeds = []string{ + "https://georgerrmartin.com/notablog/feed", + "https://100r.co/links/rss.xml", + "https://emersion.fr/blog/rss.xml", + "https://linuxwit.ch/feed.xml", + "https://andrewkelley.me/rss.xml", + "http://antirez.com/rss", + "https://drewdevault.com/feed.xml", + "https://emilydamstra.com/feed", + } + return f +} + +func FetchRecentFriendPosts() []string { + feeds := GetFeeds() + + var bunchOfBlogLinks []string + for _, feed := range feeds.FriendFeeds { + f, err := rss.Fetch(feed) + if err != nil { + log.Printf(err.Error()) + } + + 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 + } + } + } + return bunchOfBlogLinks +}
M go.modgo.mod

@@ -1,3 +1,5 @@

module git.j3s.sh/j3s.sh go 1.16 + +require github.com/SlyMarbo/rss v1.0.1 // indirect
A go.sum

@@ -0,0 +1,4 @@

+github.com/SlyMarbo/rss v1.0.1 h1:fiaIU5UhcXauVOniHOIocWG7uj8Ej6pHNarMGPJilzA= +github.com/SlyMarbo/rss v1.0.1/go.mod h1:JNF+T33oj4m5WLCQXpBTCgO+SxRbYVgdiiimHNgzcbA= +github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ= +github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
M main.gomain.go

@@ -7,9 +7,33 @@ "net/http"

"os" "path/filepath" "strings" + + "git.j3s.sh/j3s.sh/feed" ) +// templateData is a mega-struct that gets +// passed to every single template - put whatever +// you want in it tbh. +// +// "data" is a global object that contains arbitrary +// 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 +} + +var data templateData + +// the populate function populates the global "data" variable +// with ... data. with which to pass into templates. +func (t *templateData) populate() { + t.FriendPosts = feed.FetchRecentFriendPosts() +} + func main() { + data.populate() + fs := http.FileServer(http.Dir("./static")) http.Handle("/static/", http.StripPrefix("/static/", fs))

@@ -28,6 +52,7 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {

lp := filepath.Join("templates", "layout.html") if r.URL.Path == "/" { r.URL.Path = "index.html" + // TODO: add some arbitrary refresh handler for fetchFriendPosts } fp := filepath.Join("templates", filepath.Clean(r.URL.Path))

@@ -51,7 +76,7 @@ http.Error(w, http.StatusText(500), 500)

return } - err = tmpl.ExecuteTemplate(w, "layout", nil) + err = tmpl.ExecuteTemplate(w, "layout", data) if err != nil { log.Println(err.Error()) http.Error(w, http.StatusText(500), 500)
M templates/index.htmltemplates/index.html

@@ -1,10 +1,14 @@

{{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>the only way out is through</p></i> <p><i>fear is the mind-killer</p></i> -<h4>posts from my friends around the net</h4> -<p><i>coming soon</i></p> -<img src="/static/under-construction.gif"> +<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> +{{ end }} {{end}}
M templates/layout.htmltemplates/layout.html

@@ -27,7 +27,7 @@ <a href="https://write.as/j3s">bl0g -></a>

<a href="https://snap.as/j3s">pics -></a> </p> <hr> - {{template "body"}} + {{template "body" .}} </div></body> </html> {{end}}