Fediverse Discussion Script

Source code: https://github.com/persolb/federated_static_discussion

I wanted to allow comments on this site while keeping all the content pages static and not encouraging growth of the existing social network walled gardens. I want to publish a project or post, somebody else links to it somewhere, and the discussion can show up back on the original page. I don’t want to create the discussion first, which feels close to spam if I’m doing it myself. A Bluesky post feels fine, since it’s so minimal.

I made a small JavaScript discussion aggregator. Given a page URL, it currently looks for:

  • Lemmy submissions of that URL, including the community and comment count.
  • Bluesky posts linking to the URL, plus reply counts for each thread.
  • Webmentions, which should also catch Fediverse replies once they come back through Bridgy Fed / Webmention.io (still wiring this up).

So a page can end up showing something like:

Discussions elsewhere

Lemmy - !selfhosted@lemmy.world - 18 comments
Bluesky - 4 posts - 7 replies
Fediverse - 2 replies
Web - 1 Webmention

If nobody has discussed the page yet, it instead offers links to start a discussion on Lemmy, Bluesky, or the Fediverse.

The site is still Hugo-generated static files, with no comment server. The deploy script pre-fetchs discussion data into a JSON cache, so most visitors would only request a static file from jwbatey.com, with the JavaScript doing a live refresh if the cache is stale.

The cache is trusted for twice the page’s age when it was last fetched, floored at an hour and capped at a week, so old pages refresh rarely and new ones stay live. There is also a manual “Refresh” link once the cached discussion data is more than a day old.

Bluesky’s own search can find posts linking to a URL, but I’m going through bsky.md to avoid browser CORS restriction, then hitting the public API for current reply counts. Lemmy is easier: its API searches directly for posts submitted with a given URL. I query several large instances (lemmy.world, lemmy.ml, lemmy.ca, and sh.itjust.works) then dedupe.

The Fediverse side is slightly different. There isn’t a practical global search across every Mastodon-compatible server, so I’m using Webmentions and Bridgy Fed for those replies instead.