Skip

Mastodon replies

I love comment sections! For better or for worse, I’m someone who immediately scrolls down to the bottom of an article to see what people are saying about it. Often before reading the article itself šŸ™ˆ

Here, on my own site, I’ve also always wanted to display the feedback I get. People often point out mistakes, suggest improvements, or add context I hadn’t considered. I regularly update articles based on these conversations, trying to credit them by linking to their sites or posts. It sure would be nice to have all that feedback right below the article, wouldn’t it?

Screenshot of Mastodon client Ivory next to my replies section. Kirby (the Nintendo character) is inhaling the replies, floating on top of the replies section. Everything has a dithered GameBoy aesthetic

Comment systems

I didn’t want to outsource this to a third-party comment platform. Having to rely on any service in 2025 feels risky. How does enshittification work for comment platforms? I don’t even want to find out.

On the other hand I don’t want to run my own commenting platform either. Handling accounts, moderating discussions, dealing with spam, and all that. Nope!

I also looked into webmentions. There’s even a great Kirby plugin that handles them. But in the end it was too much overhead for me. For my own site the priority is keeping things simple.

Then I stumbled over Michael Thomas’s blog post about using Mastodon replies as comments. What a clever idea! I have a lot of trust and love for Mastodon. This means I don’t even mind forcing my readers to create an account there if they want to leave feedback on my articles. It’s a win-win! Mastodon, or rather my instance, also handles moderation and spam protection for me.

My first steps

I started with a simple frontend-only implementation based on Michael’s approach: a bit of JavaScript that fetched replies directly from Mastodon’s API and rendered them on the page. Simple and lightweight, it worked surprisingly well.

But then I realised I was hitting Mastodon’s API on every single page load. When kind people like Andy Bell or Stefan Judis share my articles, they can easily get thousands of visitors in a short time. Hammering the Mastodon API with that kind of traffic felt wrong.

Ideally, I’d cache the replies on my server and only refresh them once in a while…

A Kirby plugin!

I moved everything to the backend and created a proper Kirby plugin that fetches replies server-side.

Kirby’s built-in page cache makes sure the API is only hit once per day. At least that’s how I set it up for now.

The plugin fetches replies from Mastodon’s public API and also reconstructs the nested conversation threads. It registers a $page->mastodonReplies() page method that’s used in the built-in snippet to display the replies.

I just have to add a Mastodon post URL to my article’s content file:

Mastodon_url: https://mastodon.social/@medienbaecker/115496954893941334

If you’re using the Panel for your site, you can add a field to the blueprint like this:

fields:
  mastodon_url:
    label: Mastodon URL
    type: url

Then, in your article template, you just include the snippet where you want the replies to appear:

<?php snippet('mastodon-replies') ?>

When a page has a valid Mastodon URL, the plugin fetches and displays all replies to that post.

Pretty cool, too: the HTML from Mastodon’s API already includes helpful <span> elements with invisible and ellipsis classes to format long URLs.

I might add more customisation options in the future, but for now, it works well out of the box. Inspired by other people’s Kirby plugins, you can override several snippets to customise the output.

For example here on my own site I added site/snippets/mastodon-replies/outro.php with a ā€œJoin the conversationā€ button.

Check it out

Replies

  • Markus šŸ‘Øā€šŸ’»
  • Thomas Günther

    @markusr Thanks for the test, Markus. Here’s a nested reply šŸ¤—

  • Markus šŸ‘Øā€šŸ’»

    @medienbaecker It works! 🄳

  • Moritz Glantz #a11y

    @medienbaecker @getkirby This is a cool idea!
    I have questions. How do handle not knowing the Mastodon post URL when posting the article on your site?

    Have you automated the Mastodon post, or is it: Post article on website, copy link of post, write Mastodon post and send it, copy link from Mastodon post, add it to the blog post?

  • Thomas Günther

    @MoritzGlantz Yeah, that's exactly how I'm doing it right now. When the page doesn't have a Mastodon post URL, the "Replies" section simply doesn't show up. I might want exactly that for certain kind of articles and I like the simplicity. But there's definitely potential for automation šŸ‘

  • Felix Niklas

    @medienbaecker @getkirby it’s beautiful! Great work, Thomas.