Labertasche - a comment system for Hugo
The other day I have released the first version of a new comment system for the static site generator GoHugo .
Static site generators are generally awesome, you write the template, as well as the articles, in plain text, and the generator generates a static web page with little attack surface, other than the server. They are also providing your users with a better experience than any dynamic web page, since there is no delay between page loads other than networking.
So I have been pondering about how to bring comments to my static site, without sacrificing speed, and after discovering the data folder functionality in Hugo, gloves are off.
First of all, you need a server, and a program to receive data. There is no other way. My choice was Python here, since I am the most comfortable with it. I also chose Flask over Django, since it comes with less overhead.
There are 2 parts to the program:
- comments related routes
- the administrative backend
The backend serves as an overview of made comments, provides an opportunity to review spam and block/unblock email addresses that have been detected as spam by the anti-spam component .
The comment is checked for various exploits, such as trying to change the path of the relative url and also by the spam detection. The mail is checked against a block list of throw away mail providers and the internal block list. Then HTML tags are being removed. Last, but not least, it looks for text smileys and replaces them with their unicode equivalents.
Then there is of course all the internal stuff, such as entering it into the database and exporting the json into your
Hugo directory, where you can then commit it to git and rebuild the site. As mentioned in the docs,
I am using
hugo --watch via a systemd service for that, as it is the most convenient solution. An even more easy to do
solution is to just utilize screen, which is a program that can keep your bash running, even if you disconnect/log out
of the server, by pressing Ctrl-A-D.
You can find a more detailed explanation on the git, please do comment if there is something missing, bugs or errata. If you do not wish to comment, you can also write your thoughts to email@example.com.
ps.: Labertasche is German for someone who talks too much.