Home

Awesome

Emfed: Simple Client-Side Mastodon Feed Embedding

Twitter used to have a really convenient way to embed a feed into your website, but now Twitter is dead. Emfed is a simple replacement for Mastodon that works entirely in the browser, without a server-side component (beyond your favorite Mastodon instance itself).

To use it, put a special link like this where you want the feed to appear:

<a class="mastodon-feed"
   href="https://mastodon.social/@Mastodon"
   data-toot-limit="4"
   >follow me into the Fediverse</a>

Then include the JavaScript (probably at the end of your <body>):

<script type="module" src="https://esm.sh/emfed@1"></script>

Emfed generates some pretty basic markup for the feed. You probably want to style it to look like a proper social media feed, which you can do with plain ol' CSS scoped to the .toots selector, or you can use its provided CSS (in your <head>):

<link rel="stylesheet" type="text/css"
      href="https://esm.sh/emfed@1/toots.css">

You can customize the feed with data- attributes:

Emfed sanitizes the HTML contents of toots using DOMPurify to avoid malicious markup and XSS attacks.

Embed a Post and Its Replies

You can also embed an individual post, the replies to a post, or both. This mode lets you use Fediverse replies as a comment system for static sites, inspired by a blog post from Carl Schwan.

Use this to embed a post along with its responses:

<a class="mastodon-thread"
   href="https://mastodon.social/@Mastodon"
   data-toot-id="112011697087209298"
   >Thread from the Fediverse</a>

By default, both the original post and the replies appear. You can customize this link with data- attributes:

This mode uses the same style of markup as the user feed, so you can use the same CSS to provide style for these embedded posts.

Hacking

Type make dev to serve an example page.

Some missing features you might be interested in contributing include rendering media beyond static images (GIFs, videos, and audio), using a BlurHash placeholder before media has loaded, and optionally filtering out replies or boosts.

Alternatives

Changelog

Author

Emfed is by Adrian Sampson. It is dedicated to the public domain under the terms of the Unlicense.