Adding Fediverse comments to my blog

Quite some time ago, I read a post (in Czech) by Jirka Eischmann writing about how he connected his blog and Mastodon. It sounded really cool and I was thinking how to achieve the same. But the blog was about Wordpress. And I have a static blog. "Compiled" into html by Hugo and AsciiDoctor and then served as a static website by Nginx.

I found some software that could do some parts of it. Let’s take a look at those parts separately. First thing is making my posts visible on Fediverse. I haven’t found any template how to do it directly in Hugo. And when investigating it further I wasn’t sure whether it would be possible to join Fediverse with completely static website.

Solution might be to run additional software. There are some opensource projects that monitor RSS feed, connect to a Mastodon account and whenever there is a new article in RSS feed, they post it to the account. This could work in theory, but would require running addition service somewhere or integrate it somehow into CI/CD pipeline that deploys my blog. Side-note, isn’t it cool to have a blog, where you commit a post to a git repository, CI tests whether it compiles and then CD deploys it?

Long story short, I was playing with it and trying to get it to work and trying to figure out, where and how to deploy it and ideally how to carry over state between CI runs. Another tricky bit was how to get back the Mastodon URL to integrate it into the blog. In the end I decided that it is not worth the effort. I do a few post every year and when I do, it is not that bothersome to post it on Fediverse myself manually. I might want to post it to some legacy networks anyway. So I ended up deciding to publish articles manually, but I still wanted Fediverse comments on my static blog.

And it seems that many people do that. There are several blog posts about that. Unfortunately, I found that most of them had a compatibility issue with the software I use to serve my Fediverse account - Gotosocial. Gotosocial requires all API requests to be signed. That was incompatible with the code everyone else seemed to be using. I was investigating it a year ago and I decided that it is too much bother and postponed solving it (aka gave up). Nowadays, I probably would have tried some AI agent to bruteforce it’s implementation. But because I was lazy, I came up with a different solution/workaround.

As my profile is public, Gotosocial has a website that shows my public posts. And it also shows public replies to the posts. So I wrote a JavaScript that scrapes the web site. It actually solves some of the problems that I would have to solve myself if I were to use API. Everything is escaped already, relevant metadata are attached to the post and threads have a correct structure. And as I’m self-hosting, I have the deployment process under control, so my solution wouldn’t break randomly, but only when I upgrade. Only thing I needed to do was to add a right selector and few bits of CSS.

In the end, as you can see, the changes are really simple and straight forward. I consider it another victory for my laziness. I could have written a ton of code to do it via API, which might be more stable, but it would take a lot of effort. This way, I’m abusing work already done by the software I use to be on Fediverse in the first place. And it works quite nicely. Unfortunately, due to my posting speed, I got to try it only at the beginning of this year and it took me another few months to write about it. But I think it is useful and might be inspiring to the others, so I wanted to share the idea.