Comments
Fri, Jul 10, 2020 · 3 minute readhugo
Looking for a way to add comments to your static site?
Look no further.
There are many ways comments can be added, the best recent summary I found was by Darek Kay.
I was looking for something self hosted which narrowed the selection down to 9, the most well know of those prossibly being Discourse.
However, most of the self hosted platforms are overkill for what I wanted or they use a complicated (compared to the rest of the site) stack involving npm, gulp, etc.
One stood out though, Commento.
It’s written in Go so the install is extremely simple. The only downside is the requirement for Postgresql as the back end database.
In common with most of our sites, Commento is running in a container, acccessible from the internet via Wireguard.
The installation is straightforward, run as root.
* Create a directory for the install, I used /opt/commento
. cd to that directory after creation.
* Get the software, check the releases page for the current download URL.
wget https://dl.commento.io/release/commento-v1.8.0-linux-glibc-amd64.tar.gz
* Change owner:group on the install directory and everything below it.
This was a default Ubuntu server install so I used ubuntu
as the user.
chown -R ubuntu: commento/
* Install Postgresql
apt install postgresql
* Create user and database
su - postgres
$ createuser --interactive
Enter name of role to add: ubuntu
Shall the new role be a superuser? (y/n) y
$ createdb commento
Make sure to give the newly created database account a password
psql postgres=# alter user ubuntu with password 'YourPasswordHere';
Setup the Commento configuration file
I chose the configuration file but it’s also possible to set environment variables in the service file.vi /opt/commento/commento.conf COMMENTO_ORIGIN=https://your.domain.name # Bind address is optional, needed if server has multiple NIC's COMMENTO_BIND_ADDRESS=10.1.1.1 # Post to use, default is 8080 COMMENTO_PORT=8080 # This should prevent new owners registering, I found it didn't do that COMMENTO_FORBID_NEW_OWNERS=true # Postgresql connect string COMMENTO_POSTGRES=postgres://ubuntu:YourPasswordHere@127.0.0.1:5432/commento?sslmode=disable # SMTP details, for notifications COMMENTO_SMTP_HOST= COMMENTO_SMTP_USERNAME= COMMENTO_SMTP_PASSWORD= COMMENTO_SMTP_PORT=587 COMMENTO_SMTP_FROM_ADDRESS=
Setup systemd service file
vi /etc/systemd/system/commento.service [Unit] Description=Commento daemon service After=network.target postgresql.service [Service] User=ubuntu WorkingDirectory=/opt/commento ExecStart=/opt/commento/commento Environment=COMMENTO_CONFIG_FILE=/opt/commento/commento.conf [Install] WantedBy=multi-user.target
Start the service and check it’s status
systemctl start commento systemctl status commento # enable the service for start on boot systemctl enable commento
Connect to your URL and register an owner
Login as the owner you just created and register a domain
The only details needed to register a domain are a name and the domain name (including sub domain if used).Add the following snippet to your website pages
<script defer src="https://your.domain.name/js/commento.js"></script> <div id="commento"></div>
If you are using Hugo then one place this can be added is themes/theme-name/layouts/post/single.html, e.g.
Comment on this article using form below. Requires email login only for authentication. HTML forbidden, Markdown only. <script defer src="https://your.domain.here/js/commento.js"></script> <div id="commento"></div> <noscript>Please enable JavaScript to view comments.</noscript>