small pixel drawing of a pufferfish j3s.sh

Massive refactor, simplify feeds, update homepage
Jes Olson j3s@c3f.net
Sun, 17 Jul 2022 22:39:53 -0500
commit

e731c8792fbd24348ffa94465c3fba7c2043b594

parent

2f244cbe5d71cd4a5968f6ba4a0e871755b38a47

3 files changed, 142 insertions(+), 109 deletions(-)

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

@@ -1,102 +1,55 @@

package feed import ( - "fmt" - "log" - "sync" - "time" - "github.com/SlyMarbo/rss" ) -type feeds struct { - FriendFeeds []string - CompanyFeeds []string - RandomFeeds []string +var lovelyFeedList = []string{ + "http://antirez.com/rss", + "https://100r.co/links/rss.xml", + "https://andrewkelley.me/rss.xml", + "https://begriffs.com/atom.xml", + "https://blog.jse.li/index.xml", + "https://blog.tildes.net/all.atom.xml", + "https://coderanger.net/atom.xml", + "https://cyberia.club/blog/blog.xml", + "https://davebucklin.com/feed.xml", + "https://drewdevault.com/feed.xml", + "https://emersion.fr/blog/rss.xml", + "https://emilydamstra.com/feed", + "https://facklambda.dev/atom.xml", + "https://frame.work/blog.rss", + "https://georgerrmartin.com/notablog/feed", + "https://go.dev/blog/feed.atom", + "https://herman.bearblog.dev/feed/", + "https://kattraxler.github.io/feed.xml", + "https://linuxwit.ch/feed.xml", + "https://matrix.org/blog/feed", + "https://rodarmor.com/feed/feed.xml", + "https://sanine.net/rss.xml", + "https://sequentialread.com/rss", + "https://sourcehut.org/blog/index.xml", + "https://spencerkrum.com/index.xml", + "https://staffeng.com/rss", + "https://tilde.team/~kiedtl/atom.xml", + "https://www.bitquabit.com/index.xml", + "https://www.namecoin.org/feed.rss", + "https://www.ryanprior.com/posts/index.xml", } -func GetFeeds() feeds { - f := feeds{} - f.FriendFeeds = []string{ - "https://begriffs.com/atom.xml", - "https://blog.jse.li/index.xml", - "https://coderanger.net/atom.xml", - "https://davebucklin.com/feed.xml", - "https://facklambda.dev/atom.xml", - "https://kattraxler.github.io/feed.xml", - "https://sanine.net/rss.xml", - "https://sequentialread.com/rss", - "https://spencerkrum.com/index.xml", - "https://www.bitquabit.com/index.xml", - "https://www.ryanprior.com/posts/index.xml", - "https://100r.co/links/rss.xml", +// todo: update feeds once in awhile? every 30 mins? hour? +// todo: async +// feed.GetAll +func GetAllFeeds() []rss.Feed { + var feeds []rss.Feed + for _, f := range lovelyFeedList { + feed, err := rss.Fetch(f) + if err != nil { + panic(err) + } + feeds = append(feeds, *feed) + // fetch the feed, add it to the list } - f.CompanyFeeds = []string{ - "https://blog.tildes.net/all.atom.xml", - "https://cyberia.club/blog/blog.xml", - "https://frame.work/blog.rss", - "https://go.dev/blog/feed.atom", - "https://matrix.org/blog/feed", - "https://sourcehut.org/blog/index.xml", - "https://www.namecoin.org/feed.rss", - } - f.RandomFeeds = []string{ - "http://antirez.com/rss", - "https://andrewkelley.me/rss.xml", - "https://drewdevault.com/feed.xml", - "https://emersion.fr/blog/rss.xml", - "https://emilydamstra.com/feed", - "https://georgerrmartin.com/notablog/feed", - "https://linuxwit.ch/feed.xml", - "https://rodarmor.com/feed/feed.xml", - "https://staffeng.com/rss", - "https://tilde.team/~kiedtl/atom.xml", - "https://herman.bearblog.dev/feed/", - } - return f + return feeds } -func FetchFriendFeeds() []rss.Feed { - feeds := GetFeeds() - var friendFeeds []rss.Feed - var wg sync.WaitGroup - var m = sync.Mutex{} - wg.Add(len(feeds.FriendFeeds)) - for _, feed := range feeds.FriendFeeds { - go func(feed string) { - defer elapsed(feed)() - defer wg.Done() - log.Printf("feed is being fetched %s\n", feed) - f, err := fetchFeed(feed) - log.Printf("feed has been fetched %s\n", feed) - // maybe remove this if it becomes unuseful - if err != nil { - log.Printf("error fetching feed %s", feed) - return - } - log.Printf("locking mutex for %s\n", feed) - m.Lock() - friendFeeds = append(friendFeeds, f) - log.Printf("unlocking mutex for %s\n", feed) - m.Unlock() - }(feed) - } - wg.Wait() - return friendFeeds -} - -func fetchFeed(url string) (rss.Feed, error) { - f, err := rss.Fetch(url) - if err != nil { - var empty rss.Feed - return empty, err - } - return *f, nil -} - -func elapsed(what string) func() { - start := time.Now() - return func() { - fmt.Printf("%s took %v\n", what, time.Since(start)) - } -}
M main.gomain.go

@@ -3,6 +3,7 @@

import ( "bytes" "fmt" + "time" "html/template" "io" "log"

@@ -28,7 +29,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 { - FriendFeeds []rss.Feed + Feeds []rss.Feed TitleWord string }

@@ -37,15 +38,26 @@

// the populate function populates the global "data" variable // with ... data. with which to pass into templates. func (t *templateData) populate() { - t.FriendFeeds = feed.FetchFriendFeeds() + t.Feeds = feed.GetAllFeeds() + // refresh all rss feeds periodically + for range time.Tick(time.Minute * 30) { + log.Println("updating feeds tbh") + for i := range t.Feeds { + err := t.Feeds[i].Update() + if err != nil { + log.Println(err) + } + } + } } func main() { - data.populate() + go data.populate() fs := http.FileServer(http.Dir("./static")) http.Handle("/static/", http.StripPrefix("/static/", fs)) + http.HandleFunc("/feed", feedHandler) http.HandleFunc("/feed.atom", atom.Handler) http.HandleFunc("/age.html", serveAge) http.HandleFunc("/ip", ipHandler)

@@ -64,7 +76,6 @@ 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))

@@ -212,3 +223,20 @@ } else {

fmt.Fprintf(w, "not found\n") } } + +func feedHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, `<!doctype html> +<html lang=en> +<head> +<meta charset=utf-8> +<title>j3s's rss feeds</title> +</head> +<body>`) + // todo: finish this + // todo: sort them + for _, f := range data.Feeds { + for _, i := range f.Items { + fmt.Fprintf(w, "%s\n", i.Link) + } + } +}
M templates/index.htmltemplates/index.html

@@ -1,19 +1,71 @@

{{- define "title" }}j3s.sh{{- end }} {{- define "body" }} -<h4><p>hello. my name is jes. welcome to my little piece of the internet.</p></h4> -<marquee><p><i>i am Government Man, come from the government. the government has sent me</p></i></marquee> -<marquee direction="right"><p><i>I don't wanna behaaave and I'm don't wanna live up to your ssstandards</p></i></marquee> -<h4>email me!</h4> -<p>i love getting email. from anyone. from you! it's my favorite way to talk. email me anything! seriously!</p> -<p>j3s@c3f.net</p> +<h4><p>welcome, traveler. sit down, and stay awhile.</p></h4> +<marquee><pre> + *whispers* hello friend HACK THE PLANET 🌎 🐡 it's a unix system. i know this. we're all pilgrims and strangers, and nobody knows what the fuck they're doing. never feel certain. sureness is sin. feel good. pride. confidence. effortless. present. feel bad. doubt. anxiety. potential. past. it's you. it's us. we'll make it. of course. we all must make it. because someday it'll be over. like a great big dream. i hope we can wake up together. and laugh at our efforts completely gone. and gaze into each others eyes for eternity. i want so badly to see you again. +💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀💀 +</pre></marquee> +<h4>email me pls đŸĨē</h4> +<p>i love getting email. from anyone. it's my favorite way to talk. email me anything, seriously! it always brightens my day.</p> +<p>i may not respond to everything, but i read everything. i'm going through a lot of life changes rn and don't have much energy. i love you all.</p> +<p>email me at <code>j3</code><code>s&commat;c</code><code>3</code><code>f.n</code><code>et</code></p> <h4>important quotes</h4> -<p><i>unless someone like you cares a whole awful lot, nothing is going to get better. it's not.</i></p> -<p><i>the only way out is through</p></i> -<p><i>fear is the mind killer</p></i> -<p><i>everything i do is stitched with her color</p></i> -<p><i>āĻšā§āĻŽā§</i></p> -<h4>recent posts from my friends on the web</h4> -{{- range $feed := .FriendFeeds }} +<details> + <summary>0</summary> + <code>unless someone like you cares a whole awful lot, nothing is going to get better. it's not.</code> +</details> +<details> + <summary>1</summary> + <code>the only way out is through</code> +</details> +<details> + <summary>2</summary> + <pre>your absence has gone through me +like thread through a needle. +everything i do is stitched with its color.</pre> +</details> +<details> + <summary>3</summary> + <code>i am the master of my fate, i am the captain of my soul</code> +</details> +<details> + <summary>4</summary> + <code>fear is the mind killer</code> +</details> +<details> + <summary>5</summary> + <pre> +this, then, is the human problem: + - there is a price to be paid for every increase in consciousness + - we cannot be more sensitive to pleasure without being more sensitive to pain + - by remembering the past, we can plan for the future + - but the ability to plan for pleasure is + offset + by the ability to dread pain, and to fear the unknown + +furthermore, the growth of an acute sense of the past and the future +gives us a correspondingly dim sense of the present + +in other words: + we seem to reach a point where the advantages of being conscious + are outweight by its disadvantages + where extreme sensitivity makes us un-adaptable + under these circumstances we feel in conflict with our own bodies + and the world around them, and it is consoling to be able to think + that in this contradictory world we are but + ~*~strangers and pilgrims~*~ + +for if our desires are out of accord with anything the finite world +can offer, it might seem that our nature is not of this world + +that our hearts are made, not for the finite, but for *infinity* + +the discontent of our souls would appear to be the sign and seal + + of their divinity</pre> +</details> +<h4>posts from my friends</h4> +{{- range $feed := .Feeds }} <li> <a href="{{ (index .Items 0).Link }}">{{ (index .Items 0).Title }}</a> {{- if $feed.Title }}

@@ -23,5 +75,5 @@ <small> | {{ $feed.Description }}</small>

{{- end }} </li> {{- end }} -<p><i>note to my friends: add a blog title pl0x :D</i></p> +<p>😮‍💨</p> {{- end }}