Everything shared from my site to Mastodon runs out of a single all activity RSS feed. You're welcome to subscribe to it, but it's formatted with soci

Syndicating an RSS feed to Mastodon using a Cloudflare worker

submited by
Style Pass
2024-09-22 20:30:02

Everything shared from my site to Mastodon runs out of a single all activity RSS feed. You're welcome to subscribe to it, but it's formatted with social syndication in mind — emojis, hashtags and truncation that match that use case. This feed is populated from a fairly verbose processContent collection. It also populates my sitemap and search index since there's plenty of overlap in format and the data being handled. Anyways.

Syndicating this all activity feed is now being handled by a Cloudflare worker. The worker checks the feed every 15 minutes and once upon the completion of a build[1]. Doing this required adding a few new dependencies (some workers share dependencies with the 11ty part of my codebase, some don't): fast-xml-parser and html-to-text.

We have a scheduled call to the handleMastodonPost function and a fetch method that handles POST requests to the worker (the latter can only be triggered by requests that include a secret). Cloudflare offers deploy webhooks to trigger Cloudflare Pages deploys — to trigger this worker, I'm using a notification webhook. These can be configured in the settings for your pages project: navigate to notifications > destinations, create a webhook, give it a name, enter the URL for your worker (available from the card for your worker in the Overview of your workers and pages in the Cloudflare dashboard) and add the randomly generated secret to be sent to your worker. Phew.[2]

Leave a Comment