So I decided to start a blog using a static website generator. Creating a blog made only of static web pages, without any scripting language nor database, presents many advantages:
- Performance (what can be faster than plain cacheable HTML?)
- Low security risks (no script/SQL injection)
- Easy maintenance (the git repository is the backup, redundant deployment is a breeze) Finally, I like the idea of using the tool that is closest to the need, giving a feeling (if not reality) of efficiency: why using a full software stack to manage a bunch of articles?
After tinkering with various tools, including Python-based Pelican, I choose Hugo because of the large features set it provide as well as its rich choice of themes.
Setting up the site and applying “Future Imperfect Slim” was quick and easy. I even discovered in the documentation of the site that I could add comments to the static site using Staticman open source software.
The following scheme describes how commenting is implemented on a static site.
- A comment is entered in a form on the website.
- Content of the form is sent to Staticman hosted somewhere, often on Heroku under a free hosting scheme
- Staticman translates the content of the form as a push request in Markdown on a git repository (initially GitHub, since V3 also GitLab and FramaGit).
- Repository owner can accept push request and trigger site updates using HUGO
It is not straightforward, with steps hard to debug, but seemed … doable. Here is what I did.
First attempt: according to the theme maintainer
Patrick Collins did a wonderful work in documenting the theme he ported to HUGO. Among the wiki pages there is one dedicated to the setup of Staticman. To process is the following:
- Deploy Staticman on Heroku using the “Deploy to Heroku” button on the Staticman repository
- Set up a Git provider to store created comments. I began by testing the Gitlab approach. … For security reason, a Gitlab bot, in charge of pushing the comments, must be created. It is a Developer account.
- Configure Staticman on Heroku by setting variables in the dashboard. It includes the Gitlab token of the created account.
- Set up comments in the Future Imperfect Slim Hugo theme by activating in
config.toml
. - Set up Staticman itself in
staticman.yml
. At this level, reCAPTCHA can also be activated.
Result: Staticman is up and running but everything else fails and no comment is pushed in Gitlab repository.
Second attempt: according to DEV.to article
I stumbled upon a full description of the process on DEV.to, but this time using GitHub.
- Set up a GitHub repository for the comments
- Create a GitHub account only used to push comments in the comment’s repository
- Deploy Staticman on Heroku using the “Deploy to Heroku” button on the Staticman repository
- Configure Staticman on Heroku by setting variables in the dashboard. Also create a private key for Staticman.
- Set up comments in the Hugo site, this time by adding a form in the theme. This was skipped with “Future Imperfect Slim” theme.
- Set up Staticman itself in
staticman.yml
. At this level, reCAPTCHA can also be activated.
Result: No Pull Request appear in the GitHub repository.
Variants of the second attempt
The following pages describe a similar process. A grabbed additional information like details on setup of the GitHub account.
- “Running Staticman on Hugo Blog With Nested Comments” on the pages of Yasoob Khalid.
- “Configuring Staticman Comments with Hugo” on Julio’s Blog.
Third attempt: using several posts based on the Gitlab solution
The more you search, the more you find. It ended with a dozen different descriptions of the deployment and use of Staticman with HUGO. The result has boiled down to three approaches:
- From Vincent Tam, with documentation of a HUGO theme with comment on Gitlab and a blog post on deployment of Staticman on Heroku with a lot of valuable comments.
- Tiago Gomes, aka tacgomes, described all the steps required to host a HUGO site in Gitlab and enable comments with Staticman. THe short but dense article covers everything.
- Team Parallax aims to detail in two articles how to use self-hosted Staticman with GitLab (part 2 here). In fact the posts mostly cover deployment and setup of Staticman on a given server. It is minutely described but does not cover the whole process.
Results, so far
At end of February 2021,
- Staticman runs on Heroku but tests on self-hosting failed.
- Every attempt, either on GitHub or Gitlab failed: no push request correspond to a comment appeared.
- The process is hard to debug, and I have trouble locating the problem:
- Does the content of the comment form reach Staticman? REST requested must be examined.
- Does Staticman complain? I don’t think I’m fully exploiting the tool set (dashboard, console, …) provided by Heroku to debug applications.
Next steps will be, if no other information found,
- Fresh installation of the whole tool chain using a test site.
- First on Gitlab, with Staticman on Heroku.
- Then with a self-hosted Staticman if first test fails.
- If all fails, then test of an alternative with Utterances commenting system. There is at least on example of successful use with HUGO and the theme I selected.