Mastodon Comments
Around this time last year, I started working on this blog. It was a project I really got my teeth into, and I had a few must-haves. The biggest was that I wanted it to be a static site - just files on a server - with no backend, database, admin, or maintenance required. I also wanted to have the whole thing run on files - markdown in particular - so whatever I wrote was easy to reuse and repurpose but stored and accessed without needing a website or technology to run.
I set up the site using Eleventy (11ty) to do all this. I’d been a Jekyll user before and had encountered a few limitations that 11ty didn’t have. Being built in JavaScript rather than Ruby meant there was a larger community of developers engaged and a lot more portability of code.
One of the missing features of a static site is the lack of Web 2.0 features that enable user-generated content, such as comments. So essentially, the site has been operating as an OG weblog - and I liked that. Just me and some words
Then along comes agent provocateur Jim Groom:
To be honest over the last year I have looked at a few options to add comments but I didn’t find many that didn’t leverage specific publishing systems (Netlify, GitHub) or weren’t a paid for service. Given this site currently costs me the fee for the domain and that’s it - paying for a service is not a cost I will bear. Also, IM not doing this site for clicks or user engagement, the only metric I’m worried about is my output and post count. and while the site currently sits on GitHub Pages given the current rate of enshitification I didn’t want to move away from having the freedom to FTP the site anywhere and point the domain at somewhere new.
So at Jim’s behest, and using it as motivation I resumed my search, but this time I went to the search bar with a specific question – can you use Mastodon for comments?
I started here because I could see that Mastodon and ActivityPub could be an awesome way of combining blogs and interactions into the future. And while my simple 11ty blog wasn’t going to be able to run as an ActivityPub server - it had a lot of what’s needed to connect into that eco system.
And what I found was, Yes! Yes you can use Mastodon for comments. A number of posts discussed how they’d gone about it, were sharing their code - so I thought how hard could it be?
Well surprisingly simple! In about an hour I’d managed to copy the code, integrate, test and style it - and as a version 1.0 I’m very happy.
How does it work?
On my end I copied the code that Casey wrote - his comments template (which includes the js file) and the associated css files for the comments and avatars.
From there I made a couple of tweaks to the variables used - and added those to my template metadata.
commentUsername
= your Mastodon name (the first @)
commentHost
= your Mastodon host (the second @)
commentId
= the Mastodon post ID that refers to the blog post
I tweaked the setup for 11ty - so I've put the comments template as a Partial that I can include in my template and I have the template pull in the comments section only if there is an Mastodon post ID is linked. This was to give me an opt in to comments - some posts I might not want them at all.
I’ve already set up EchoFeed which automatically posts to Mastodon via the sites RSS. So once I've got that post - I can add the idea back into the post and republish. So rather than automatic there is a manual step - but it also gives me the power to opt in and out. Choices are a good thing.
If there is a comment ID attached to the post then the template will pick that up and add the comment template - which all works client side via the Mastodon API:
{%- if commentId | length -%}
{% include "partials/comments.njk" %}
{% endif %}
And from my end that's it. I found Fabrizio Musacchio's post which added some other features - an API token so you can get more than 60 replies etc. But I also noted that he's not using his own Mastodon comments on the site... not sure why. I'll keep looking at this and see if any other features might be useful to add and poke around old posts and see which ones to add comments to.
Comments
Comment on this blog post by publicly replying to this Mastodon post using a Mastodon or other ActivityPub/​Fediverse account.
No known comments, yet. Reply to this Mastodon post to add your own!