đ± adding a comments section to a static site
Assumed Audience: You have a blog, most likely a static site hosted on Github Pages or another static site hosting system. You want to enable a comments section, or at least a way for readers to contact you, but you donât know how.
The biggest risk in making a personal site is that you fall down the rabbit-hole of customization. Part of why I designed my site to look like Craigslist is to resist that urge. And yet here we are, talking about how to implement webmentions like itâs something folks have been asking me for. Here we go.
(If you know what webmentions are already, feel free to skip to âHow does it work?â. And if you donât care how it works, skip to âPick a serverâ).
What is a webmention?
A webmention is a simple way to notify any URL when you mention it on your site. Itâs like getting an @-mention on Twitter, except interoperable across any site. If Facebook and Twitter both supported webmentions, you could @-mention a Twitter user in your Facebook posts.
How does it work?
The Webmention site has a clear walkthrough, but in the context of commenting1 you can think of it like this:
Letâs say Alice uses her phone to comment on Janetâs tweet.
- Aliceâs phone talks to Twitterâs computers and says âHey! Iâm Alice, hereâs my comment on post 3526.â
- Twitterâs computers say âGot it, thanks!â
- Later, when Miaâs phone goes to look at her tweet, it asks Twitterâs computers âHey, Iâd like to look at post 3526.â
- Twitterâs computers say âOkay! Hereâs the text and here are all the comments, including this one from Alice!â
Webmentions works the same way, except its across all websites, not just Twitterâs. So it needs to take one additional step. Letâs assume again that Alice is using her phone to send a webmention:
- Aliceâs phone goes to Janetâs website and says âWe have a comment! Does your site support webmentions?â
- Janetâs website replies âYes! Send them to computer Xâ
- Aliceâs phone then goes to Computer X and says âHere is my comment for Janetâs post at url
www.janet.com/y.html
â. - Computer X says âGot it, thanks!â
- Mia goes to Janetâs website and asks âCan you render
www.janet.com/y.html
?â - Janetâs website quickly goes to Computer X: âHey, got any webmentions for me?â
- Computer X: âYup! Alice wrote this.â
- Janetâs website then responds to Miaâs phone: âYup! Hereâs
www.janet.com/y.html
! Iâve rendered the comments at the bottom.â
If you have a static site, you probably donât have a computer X thatâs always available to store messages from random people. This site currently runs on Github Pages which just serves files, it doesnât accept new messages. So if youâre running a static site like I am, you need a slightly different approach.
1. Pick a server
If you have a server, go for it. But if you donât, you need to find a webmentions service you can use. Webmentions.io is an open source, free option. You sign in with IndieAuth and itâll make an account for you. Easy peasy.
2. Follow setup instructions.
Youâll notice that in the Settings tab, webmentions.io gives you two link tags to put in your HTML header. (You can see that I put mine here with the url stored in my config file. I recommend that for the next step). This allows someone like me to come and ask âHey, whereâs your computer X?â and quickly find the answer. Youâll also notice that it gives you an RSS feed you can follow to track webmentions you receive. You can follow it in your RSS reader of choice, or even write some code to display the mentions on your site!
Thatâs all you need to do to receive webmentions. But how do you support people sending them? IndieWeb folks in the know have their own systems to send you webmentions, but what if you want to support a comments section on your site?
3. Create a comments section
Aaron Parecki has a great post on sending your first webmention and making it render right. At the bottom of his post, youâll notice a little form. It says âHave you written a response to this? Let me know the URL:â and then has a place for you to paste your comment. While I havenât seen any tutorials on how to do this, itâs actually something webmention.io supports for you! You can see my version at the bottom of this page.
If your username for webmention.io is x.com, visit https://webmention.io/x.com/webmention
. Youâll see a form nearly identical to what you want on your site. With some slight tweaking of the html, you can get something like this:
<form action="{{site.webmention_link}}" method="post" target="_blank" style="margin-top: 16px;">
<label for="source">Comment by responding wherever you'd like and send me the URL:</label>
<input type="url" name="source" id="source" placeholder="The link to your comment" style="margin-bottom: 14px; width: 90%; display: block;">
<div hidden>
<label for="target">Link to the page you're commenting on:</label>
<input type="url" name="target" id="target" value="{{site.url | append: page.url}}" placeholder="The page your webmention is about (probably this page)" style="margin-bottom: 14px; width: 90%; display: block;">
</div>
<div style="margin-top: 16px;">
<input type="submit" class="button" value="Send Webmention">
</div>
</form>
Add that to the bottom of your post template and voila!
Thatâs all you need to enable people sending comments to you. But what about displaying those comments?
Iâve personally not chosen to do this yet. But there are a few tutorials online like Deluviâs or Rowan Manningâs. If youâre looking for display inspiration, I recommend Maggie Appletonâs site.
Info:
- Related to:
- đł how I publish my Zettelkasten
- đ± how to comment
- [[đ° itâs not about writing, itâs about thinking]]
- Also posted on IndieNews
-
Webmentions allow you to do everything from comment to like to bookmark, and more! Weâll talk strictly about commenting for now, but if you replace the word âcommentâ with âlikeâ in this section, itâs all still true. ↩
Every post on this blog is a work in progress. Phrasing may be less than ideal, ideas may not yet be fully thought through. Thank you for watching me grow.
Updates
- : Significant improvements to 'how it works' section including diagrams.