Enabling Comments in Hugo with Isso
There are a lot of great reasons to use a static site. One of the challenges for a blog based on a static site generator like Hugo is incorporating a comment system. In this post, we’ll walk through adding a comment system using Isso, a self-hosted and open-source comment library.
Isso?
Isso is an open-source comment server which you host on your own infrastructure. Comments are written in Markdown and stored internally in a SQLite database. All you need to do is run the server and embed the script in your template. It has several big advantages:
- Because it is hosted on your own infrastructure, nobody else has control of your data, and in particular nobody can make money off your users
- There isn’t a lot of complicated web programming needed
- It’s very simple
Of course, it does have drawbacks:
- You have to be able to host a comment server
- You need to be proficient with some basic terminal skills and willing to debug things when they break
- It’s not one of the built-in comment systems supported by Hugo
- Hosting a server on your own infrastructure is not without security risks
Following in the footsteps of several other authors on the subject1, let’s walk through what’s needed in order to add comments to our blog.
Server hosting
The first thing we’ll need is an Isso server up and running. To obtain this you will need to have a server accessible to the public internet, such as one of the following:
- A Raspberry Pi, spare laptop or similar
- A headless VM on a server you already have
- A cloud server
There are lots of resources for hosting things in the cloud, and this is a viable option. Similarly, hosting something on a small box like a Pi is a great project. Since I already have a dedicated VM host running Proxmox, I decided to deploy Isso as a Docker container. It’s possible to run Isso directly but the ability to redeploy resources more easily makes Docker a win in my book.
We want users to be able to subscribe to replies to their comments. Other comment services like Disqus handle this for us but for any self-hosted solution we’ll need to work it out. It’s completely possible to host our own mail server, but it’s a mountain of work to manage it. A much simpler solution is to use a third-party solution like Mailgun. Sign up for a free account (you’ll need to enter a credit card but won’t need to pay anything).
Prerequisites
Before we continue, let’s make sure we have our infrastructure setup. Our host machine looks like this:
- Running Ubuntu2, though basically any Linux distribution will look substantially similar to this.
- Docker and Docker-Compose are installed.3
- Our gateway is setup for port forwarding HTTPS traffic4.
- We have a web server/reverse proxy set up and configured.5
- We have a Mailgun account setup with a key.
Once our host is ready we can proceed.
Docker-compose
We’ll add the following to our docker-compose.yml
:
|
|
In this code, we’ll replace the following:
Variable | Meaning |
---|---|
DIR |
Directory on the host, which contains the Isso config and database. Make sure it is owned by the user which runs docker-compose . |
PORT |
The port on the host which maps to the Isso container. You can leave this entry out if you aren’t using 8080 for anything. |
UID |
The user ID of the user which owns DIR . |
GID |
The group ID of the user which owns DIR . |
Reverse proxy with nginx
Next we’ll add a config file so that our web server will point requests to the
container as a reverse proxy. If you are using the Swag container from
Linuxserver.io (and I recommend that you do) you can add this to your
swag/nginx/site-confs
directory as isso.conf
:
|
|
Note here we need to set ${PORT}
to match what was used in the
docker-compose.yml
file. (If you removed the entry just use 8080
)
Isso config
Now we’ll setup our Isso config file at ${DIR}/config/isso.cfg
:
|
|
You’ll need to edit a number of the entries in this config file to match your setup, using info from your Mailgun and server config.
Edit Hugo template
Next up we’ll need to edit our blog template to add the comment form. This part
is pretty easy but will have one wrinkle to deal with. The specific file you
need to edit will depend on your template, for mine I edit
layouts/partials/comment.html
and add the following:
|
|
Make sure to edit ${ISSO_URL}
to match your hosted Isso instance.
Start Isso
This part is simple, just run docker-compose up -d
to start the container.
Once it’s up and running, we should be able to load any of our posts and see a
comment form at the bottom.
Final thoughts
This setup is pretty basic. You can customize it further by using some CSS or further customizing the template. That said, it fulfills the basic needs pretty well, and does so without selling our users' data.
-
See StÃobhart Matulevicz and Kevin Masson. ↩︎
-
I prefer to use LTS distributions when possible. As I am writing this that means Ubuntu 20.04. ↩︎
-
For more on installing Docker (or any other Linux tools, really) I recommend the extremely well-written Digital Ocean tutorials. ↩︎
-
This is a complicated topic with a lot of system-dependent details, probably Port Forward is the best place to get started learning about it. ↩︎
-
Another big topic. For brevity, I’ll suggest just going with a Swag container, that’s what I use. ↩︎