About my comments implementation
The source code for the comments, like all the other source code for my blog system, is in this git repository. Of particular interest is the code in
comments.go contains fairly simple code to display and store comments and provide a backend page that allows me to delete comments.
To prevent spam,
captcha.go comes into play. This provides a Go HTTP middleware to display a captcha to be solved for requests. If someone wants to create a new comment, a captcha is displayed and if successfully solved, the original comment submission request is executed and it is stored in a cookie with a JWT token that the captcha was solved. Captchas are created using a captcha library.
After a comment is saved, a webmention is created with the post’s destination and I can accept or reject the comment in the webmention backend. If I click to accept, the comment will be displayed under the post.
One thing to keep in mind, however, is that my blog is no longer a static site. The comment feature is one of the features (like search) that would probably have been much harder to implement with a static site. I used to be a fan of static sites, too, but static sites also have limits on what functionality is possible and what is not.