Mastodon as comment system for your static blog
Comment systems are an essential part of modern websites, providing a platform for users to engage with the content and share their thoughts and opinions. While there are many options available for adding commenting functionality to a website, one alternative worth considering is integrating a Mastodon thread, also known as a “toot.”
Mastodon is an open-source, decentralized social media platform that allows users to share text, images, and other types of media in a manner similar to Twitter.
The Fediverse — Mastodon
Twitter is a centralized social media platform that allows users to share short messages, called “tweets,” along with images, videos, and other types of media. Twitter is owned by a private company and has a centralized structure, which means that all user data and content is stored on servers owned and operated by the company.
In contrast, Mastodon is a decentralized social media platform that is part of the Fediverse. The Fediverse is a network of interconnected, decentralized social media platforms that use the same open-source software and protocols, allowing users on different platforms to communicate with each other. Mastodon operates on a decentralized model, meaning that it is not owned or controlled by a single entity and user data and content is stored on servers run by individual users or organizations. This decentralized model allows for greater privacy and control over user data, as well as more diverse and independent communities.
In terms of functionality, Mastodon is similar to Twitter in that it allows users to share text, images, and other types of media in short messages called “toots.” However, Mastodon also has additional features, such as the ability to boost (similar to retweeting) and favorite toots, as well as the ability to customize your profile and the look and feel of your Mastodon instance (server).
Using a third party commenting system like Disqus does involve some trade-offs, including the fact that you are giving up some control over your user data. When you use a third-party system like Disqus, the user data (such as comments, email addresses, and any personal information provided by users) is stored on servers owned and operated by Disqus. This means that you do not have direct control over this data, and you will have to rely on Disqus to properly secure and manage it.
There are a few potential disadvantages to not owning your user data when using a third party commenting system. First, you may be subject to the privacy policies and data handling practices of the third-party system, which may not align with your own policies or values. This can be especially concerning if you are collecting sensitive or personal information from your users, as you may not have control over how this information is used or shared.
Second, not owning your user data can also make it more difficult to migrate to a different commenting system or platform in the future. If you decide to switch to a different system, you may have to manually transfer all the user data from the third-party system to the new platform, which can be time-consuming and may not be possible in all cases.
Finally, using a third party commenting system can also potentially result in lost traffic to your website, as users may be directed to the third-party system’s website when they leave comments or log in to their accounts. This can be especially problematic if you are relying on advertising or other monetization methods that rely on website traffic.
Integrating a Mastodon Toot thread into your blog post
There are several potential advantages to integrating a blog post with the Fediverse, specifically Mastodon:
Increased visibility: By integrating your blog with Mastodon, you can potentially increase the visibility of your content by reaching a wider audience. Mastodon has a large and active user base, and by publishing your content on the platform, you can expose it to a new audience that may not have seen it otherwise.
Greater control over user data: Mastodon operates on a decentralized model, which means that user data is stored on servers run by individual users or organizations. This can give you greater control over your user data and how it is used, compared to using a third party commenting system like Disqus.
Improved user experience: Mastodon allows users to easily share and engage with your content, as they can simply “boost” (similar to retweeting) your toots to share them with their followers. This can create a more interactive and engaging experience for your readers.
Enhanced privacy: Mastodon has a strong focus on privacy and user control, which can be appealing to users who are concerned about the data handling practices of centralized platforms. By integrating with Mastodon, you can offer a more private and secure commenting system for your readers.
Stronger sense of community: Mastodon is known for fostering strong and independent communities, and by integrating your blog with the platform, you can potentially create a more cohesive and engaged community around your content.
The technical proposal is to have a specific toot thread per blog post, so that a Mastodon user would be able to post replies to your post in the thread itself, as any other toot you may publish in the Fediverse itself. The “only” thing left is to integrate that thread into your blog, as if those were comments from a classic system.
How? Thanks to Carl Schwan (@firstname.lastname@example.org) who shared in a blogpost the Javscript code necessary to achieve this: https://carlschwan.eu/2020/12/29/adding-comments-to-your-static-blog-with-mastodon/
This is the code that I finally ended using, heavily based on Carl’s. The main differences are:
- I’m importing the necessary libs from CloudFare’s CDN, not hosting those files directly
- Toot is automatically loaded as soon as the user scrolls to that section of the page
- and of course, the parameter names (which are based on Hugo and my modified hugo-tranquilpeak-theme)
The code snippet above code, based on a toot ID that the post must define in its metadata, fetches via JSON the whole discussion thread. Once that’s done, it’s just a matter of sanitizing the HTML (to be sure nobody can inject JS into your blog but just replying to the toot) and rendering it into the HTML.
There is a small chicken and egg issue though: you need to know the ID of the toot to use as discussion thread to specify it as part of the post metadata, but probably (although not mandatory) you’d like to include the URL of the post itself, as part of the content of the toot (and ideally the link should work as soon as the toot is published).
Yes, you can edit toots, so you would be able to publish the toot, grab its ID, change the post and publish. The problem is that you’ll be losing the momentum that publishing a new toot gives you, as the toot would initially not contain the link to the blog post itself.
So my workflow, although not ideal, is going to be as follows:
- Publish the post without Fediverse discussion enabled (no toot ID)
- Publish the toot containing the URL to the post and grab its ID
- Change the post to include the toot ID
- Republish the website
It’s not ideal, as you are potentially loosing comments from early visitor to your post, but given that publishing a static website is quite fast, it should not be that many people.
And with that, you have a fresh new comment system based on the Fediverse for your blog!
Note: I’ve kept as a fallback for existing posts (with existing comments) Disqus, so if a post does not define a toot ID, then the comments system fall backs to Disqus. Ideally I’d love to move all those posts to Mastodon threads, but I don’t think that’s possible, as you’ll need to post toots on behalf of the users that created those comments (or you can use your own account and mimick the message as if they would have post it). Maybe something to explore in the future.
Thanks again to Carl Schwan (@email@example.com) for its contribution to the community!
2023/01/01 Update — I’ve recently changed the markup (and some functionality) to include some extra features, as the botton links to boost / reply, as well as including the count. This is the latest code:
2023/01/02 Update — Quick hack to group / nest replies properly