stevegattuso
This site is an always-in-progress repository for my thoughts and ideas. You'll generally find me writing about sustainability 🍃, urbanism 🏙️, programming 💾, vegan cooking 🍛, and whatever else pops into my mind.
Comments on a static website, powered by Mastodon
Published on Mar 23rd, 2024.

I’ve been wanting to experiment with adding a comments section to posts and pages on my website for a while now. Rather than using one of those comments-as-a-service companies, I figured a lighter-weight solution would be re-using a social tool I’m already invested in: Mastodon.

I’m far from the first person who has figured out how to do this. I did some research and found a lot of implementations like this one from Cassidy James’ blog. The general idea is to have a visitor’s browser fetch the latest replies from the public Mastodon API then render in the results with JavaScript. The results look great but I wanted to avoid using JavaScript and, by proxy, the possibility of DDoSing my Mastodon instance with API requests if I ever have a popular blog post.

Instead, I threw together this Jekyll plugin which fetches Mastodon replies at build-time and allows me to render them into the site’s outputted HTML. I think this is a lighter weight approach for both visitors and my Mastodon server. It comes at the cost of new comments only appearing when I re-generate my website, but I can alleviate this pretty easily with a nightly cron job.

I’ve had success with using this technique for the hackNY webring, which fetches webring members’ blog feeds nightly and outputs a unified feed onto a GitHub-hosted static website1. It’s a clever way of keeping the simplicity of a static website while still serving dynamic content.

As for my comments implementation, I’ve enabled them for this page and would love it if you could help me test it by replying to this post. I’m sure there are bugs that still need to be ironed out so the more data I can get the better 😀.

  1. You can see the source for this mechanism here

Comments

To leave a comment, reply to this post on Mastodon. Your reply will appear the next time the site is generated.

@vesto beautiful solution. easy on everyone's resources, ability to moderate, takes out the obsessive rush of instant dynamism everywhere ... love it!

@vesto help I'm stuck in the fediverse!! 😆

@aynish hehe. I haven't added any kind of logic for handling replies to replies yet. the linked post makes it seem like I could easily find myself slipping down a rabbit hole if I try to implement some kind of threaded UI.

probably fine to punt on for the time being.

@vesto i think it's fine, threading seems unnecessary to be honest

it looks great on the web page!

@vesto Wonderful! Daily comments updates are nice. I wonder how hard it would be to get a webhook or similar to trigger a redeploy when there is a comment?

@vesto interesting! Do you have to rebuild every time a comment/reply is added? How does moderation work?

@mikebell yup- the comments are fetched each time jekyll builds.

moderation is actually interesting because it defers to how mastodon handles it. I might need to tweak the code a bit but muting/blocking someone should hide their comment in the thread.

on top of that, I can report any offending posts to the infringing author's instance admin, adding some actual consequences to being a jerk that wouldn't otherwise exist if I had a comment system siloed to my website. it's a neat accidental perk!

@vesto that's really cool. I'm going to look into doing something similar for Hugo.

@mikebell heck yeah! give me a ping if you end up doing so- would love to link to it from this post.

@vesto Neat! Just replying to get more comments on your post.

@vesto Interestingly, when I look at the thread on Mastodon I only see about three or four comments ... nothing like the number that you are seeing and including in your post.

Federation for the confusion, I think.

@ColinTheMathmo oh interesting! I suspect this may be one of those quirks of the fediverse where your instance just hasn't discovered all of the posts in the thread. I'm pulling from my instance which has the god's eye view of the responses, hence the discrepancy (if my theory is correct).

@vesto I think of posts travelling to where they have a reason to go, and most of the posts in that thread have no reason to get here.

It can be a problem. I've written a tool to chart conversations, and it's simply a truth that not everything turns up.

I'm not sure what to do about it, and whether it can be "fixed".

@ColinTheMathmo

Your chart is ready, and can be found here:

solipsys.co.uk/Chartodon/11215

Things may have changed since I started compiling that, and some things may have been inaccessible.

In particular, the very nature of the fediverse means some toots may never have made it to my instance, in which case I can't see them, and can't include them.

The chart will eventually be deleted, so if you'd like to keep it, make sure you download a copy.