A Feed Reader on a Static Site
I follow a handful of people whose writing I don’t want to miss: the Rails team, DHH, Aaron Patterson, Sailing World, the Adafruit blog. Most of them still publish an RSS or Atom feed. None of them need an algorithm between us.
So Following is a new page under Apps. It shows the latest headlines from those feeds, newest first, grouped by day. Click a headline, read the post on the author’s own site.
The catch: this site is static. GitHub Pages serves files. It can’t go fetch someone else’s feed on a schedule.
Why not fetch in the browser?
The obvious shortcut is a bit of JavaScript that pulls each feed when the page loads. Browsers block that. Most sites don’t send the CORS headers that would let another domain read their feed, so the request fails. The workarounds are a public CORS proxy (someone else’s server sees every request) or running my own proxy (one more thing to keep alive).
Doing the fetch ahead of time is simpler. The page only ever reads a file that already lives in the repo.
The shape of it
_data/following.yml the list of feeds
│
▼
GitHub Action, every 6 hours
python3 _scripts/fetch_feeds.py ──▶ each feed
│
▼
_data/feed_items.json headlines, links, dates
│ commit (only if something changed)
▼
GitHub Pages rebuild ──▶ /apps/following/
The list
Adding a feed is four lines of YAML:
- name: "Aaron Patterson"
site: "https://tenderlovemaking.com/"
feed: "https://tenderlovemaking.com/atom.xml"
tag: rails
The tag groups feeds in the sidebar. Pushing a change to this file kicks off a fetch right away, so a new feed shows up in a few minutes instead of waiting for the next scheduled run.
The fetcher
About 150 lines of Python, standard library only. No pip install step in the Action, nothing to keep updated. It:
- reads the feed list
- downloads each feed with a 20-second timeout and a size cap
- handles RSS 2.0, RSS 1.0 and Atom
- keeps the newest 10 items per feed
- writes title, link, date and source to
_data/feed_items.json
A few choices worth calling out:
- Headlines only. No excerpts, no article text. The page is a pointer to other people’s work, not a copy of it.
- Only
httpandhttpslinks survive. A feed can’t sneak ajavascript:link onto this site. Titles are stripped of HTML and escaped again when Jekyll renders them. - One broken feed doesn’t sink the run. Failures are recorded and listed quietly under the sidebar.
- No change, no commit. If the headlines match the last run, the script doesn’t touch the file. Otherwise the repo history would be a commit every six hours that only changes a timestamp.
The schedule
The Action is short. The interesting part is the end:
on:
schedule:
- cron: "17 */6 * * *"
workflow_dispatch:
push:
paths: ["_data/following.yml"]
# ...fetch, then commit if changed...
- name: Request Pages build
run: gh api -X POST "repos/$/pages/builds"
Commits made by an Action with its built-in token don’t always trigger the usual Pages rebuild, so the workflow asks for one directly. It runs at 17 minutes past the hour because everyone else’s cron jobs run on the hour.
This is the first Action on this site. Until now the rule was “Pages builds from the main branch, no Actions.” That rule still holds for the site itself. The Action only updates a data file; Pages still does the build the same way it always has.
Take the list with you
The same YAML also builds an OPML file. OPML is the standard format feed readers use for import and export. Drop it into NetNewsWire, Feedly, or anything else and you get the same subscriptions.
Tradeoffs
- Headlines can be up to six hours old. For blogs, that’s fine.
- A bot now commits to the repo, so local work needs a
git pullbefore pushing. - The list is public. That’s the point of a blogroll, but it’s worth knowing before you add something.
That’s it: a list, a script, a schedule. RSS turned 25 a couple of years ago and still does exactly what it says.