Comments on a static site? It's simpler than you think!
TL;DR: Use your access logs to get messages from users - then manually add them to your post front matter. Publish on rebuild.
Warning: This article will be of interest to a very specific - and very small -group of people.
If you:
a) like extremely hacky solutions to problems;
b) Host a static website with an Apache-based server;
c) Want a comments section, and don’t want to either rely on external service such as Disqus or Comment.io or spin up a yet another self-hosted service to handle comments for you.
You should read on. Otherwise, bugger off. You’re wasting your time here.
The basic problem
Static sites, are by their nature, static. You can’t interact with them really. They exist as a collection of HTML pages in a hierarchy on the root of your server. The attractions of a static site are many - not least security, portability, and speed.
But as a writer or site owner, you crave interaction with your readers. How do you manage it without relying on an external service?
Actually, it’s a piece of piss. A very hacky piece of piss.
Get on with it FFS
Alright. Down towards the bottom of the page, you’ll see a box which says “leave a comment.” or something like that. It’s some basic HTML and javascript which I adapted from w3schools. I’m not really a coder. I have virtually no experience with javascript and only a little with HTML. It’s included as an include called comments.html on my posts template - because we’re all about imagination here.
It's called borrowing
If you write in the box and click the submit button, your browser will push you to a relative URL based on the text, and prefaced with the string “COMMENT.”
For instance, if you wrote, “your site sucks and I hate you so much. Just go away and die.” you would be redirected to “https://thecrow.uk/COMMENTyour site sucks and I hate you so much. Just go away and die”
Obviously, that URL doesn’t exist, so you’ll be directed to a custom 404 page saying something like: “Thanks for your comment.”
With me so far? Good.
As I said, I’m running an Apache server on a Linux system (Raspbian actually), and I have access logs enabled. Not because I want to track you across the internet, but because it has historically been useful in sniffing out bots (suspiciously absent since ditching WordPress) and bad actors.
Using grep, I can find any entries in my logs which contain the string “COMMENT”
eg: grep COMMENT /thecrow.log
Will bring up the plain text comment along with date & referring URL.
Meanwhile in Jekyll...
OK. So I have the comment. Everyone hates me and thinks I’m a dick (they are correct), and I want to share their disdain with the world.
On the yaml front matter I have an array called “article_comments” Comments which I have found in my access logs are manually added to the array. Consider it as a kind of moderation queue. It’s not quite as easy as clicking ‘approve’ on WordPress - but it works.
I also have an _includes called submitted_comments.html which contains the following:
BUT IT GETS BETTER...
I can have a script called by cron at 11.59pm every day (just before logs are archived), which will echo the output to a text file - I can then inspect this this text file at my leisure - kind of like a ready-made, automated moderation queue.
I don’t doubt that there will be some unforeseen problem with this, but I can’t think of any right now.
Still with me?
If you’ve understood what I’ve written so far, well done! This has been a mess from start to finish.
But you know what? It works. Leave a comment and try to keep it to under 230 characters.
Happy new year :)
*edit 31/12/2020: For the purpose of this post, I’m approving everything which comes in. But if you could write in complete sentences, that would be nice. Shit gets tedious real fast.
This site is hosted on a Raspberry Pi 4B in the author's living room (behind the couch). If you fancy building a website, but would prefer not to have hardware cluttering up your house, you can get reasonably priced hosting from BlueHost
On the other hand, if you're worried about being followed online, consider using PureVPN to cover your tracks.
These are affiliate links. Obviously. If you're feeling generous, you can buy me a coffee.
You may also be interested in...
Leave a comment
Leave your name (or don't) and try to keep it under 230 characters. Here's how it works
Comments:
[09/Jun/2022:17:12:57 +0100] Ya shmart!-----------------
[04/Feb/2022:12:53:16] Thanks dude! I'm obscenely pleased with it myself :) - Crow
-----------------
[04/Feb/2022:06:12:21] 404 commenting on page failed successfully! Well done a clever approach.
-----------------
[09/Jul/2021:03:43:09 +0100] That is a clever approach!
-----------------
[25/Jun/2021:00:55:49 +0100] Well that's a sneaky neat approach. Love it!
-----------------
[30/Apr/2021:00:09:28 +0100] F0 9F 91 81 - edit by The Crow: That's unicode for a grinning face with smiling eyes. Apparently. This comment system does not support that. Sorry.
-----------------
[31/Jan/2021:22:45:11]Too many Klingons this morning. Ask me arse.
-----------------
[30/Jan/2021:00:47:00] You may, because other people may find it useful. I haven't given it any great in-depth research, but it looks pretty solid and a good solution. I'm going to carry on as I am - The Crow
-----------------
[29/Jan/2021:23:56:58] may i suggest https://remark42.com/
-----------------
[27/Jan/2021:23:36:00] I don't see why not, but there are probably easier ways of doing it in those cases (I don't actually know). And you're also right in that I was compelled to search up 'sonicboomkake' - I'm still none the wiser - The Crow.
-----------------
[27/Jan/2021:23:30:04] Hey, The Crow--this is actually pretty cool. I wonder if the idea can be extended to other web servers like thttpd or the httpd included with OpenBSD? In any case, well done.That reminds me: years ago, when I subscribed to writer Warren Elli's' newsletter, he mentioned that he'd find the oddest items in his search logs, like 'sonicboomkake' and the like. Now you've got it too!
-----------------
[27/Jan/2021:08:50:00] No Problem Bobby. There are no tables to drop so no harm done. Static site = no database, you see. - The Crow
-----------------
[27/Jan/2021:07:12:23] Please buy my awesome stuff at my website http://example.com/stuff Please %3Ca href=%22http://example.com/stuff%22%3Eexcuse my attempt%3C/a%3E at breaking your website. /n/n'drop tables. Bobby.
-----------------
[26/Jan/2021:19:00:27] Apache logs as a DB - Why not.
-----------------
[26/Jan/2021:12:01:00] That's a pretty good idea. I'll look into it - The Crow
-----------------
[26/Jan/2021:07:29:53] After getting the 404 page, I thought, why not add a comment input to that 404 page too, in case there is a legit 404 someone can report to you!
-----------------
[26/Jan/2021:07:26:37] This is not an error, it's a feature! I like this kind of code judo. Nice article and this makes me happy that awesome blogs like yours are alive and kicking!
-----------------
[08/Jan/2021:10:35:16] ytyty
-----------------
[05/Jan/2021:08:52:27] You're right to an extent - it does need active comment moderation if there are a lot of comments coming in - but then, so would a regular comments blog. At the moment I'm checking in two or three times a day - that will probably drop off unless I've *just* published something new. Rebuilding and pushing out takes maybe a second. One of the many benefits of being in the same physical location as the server :) - The Crow
-----------------
[05/Jan/2021:02:14:03] Pretty interesting approach! Only issue I could see is if your site becomes greatly popular overnight or something and then the comments are delayed so it stifles user discussion in the time until you decide to rebuild. But I personally think it's cool either way
-----------------
[02/Jan/2021:00:02:38] Thank you! - The Crow
-----------------
[01/Jan/2021:21:40:18] Its not stupid if it works.
-----------------
[01/Jan/2021:13:58:00] In response to 'this is stupid and can be spammed' - Well, not really. It's a manual review process. If I choose not to pull a comment from the logs, it just stays in the logs and is deleted after a day or two. Everything that appears in this comment section is here because I want it to be - I am deliberately not automating the process. Overall comment quality is low because for the purposes of this post, I'm letting absolutely everything through. When I *do* add more automation - magically echoing comments to a text file for my perusal, I will be using filters against known spammy domains, IPs, and keywords. Don't worry dude, it will be fine. - The Crow
-----------------
[01/Jan/2021:12:33:07] this is stupid and can be spammed
-----------------
[31/Dec/2020:20:50:46]assadasd
-----------------
[31/Dec/2020:19:03:05] testing if i can use it with a spam bot
-----------------
[31/Dec/2020:19:13:11] Yeah - I've not set the server up to handle long URLS and I'm guessing that's what you tried. I have no desire to change this. 230 characters is the (slightly flexible) limit. For you anyway - I can write what I want as I'm putting it direct into front matter - The Crow :)
-----------------
[31/Dec/2020:19:13:11]Bad RequestYour browser sent a request that this server could not understand.Apache Server at thecrow.uk Port 443
-----------------
[31/Dec/2020:13:00:28] Test
-----------------
[31/Dec/2020:11:20:58] Ghh
-----------------
[31/Dec/2020:11:10:43] your site sucks and I hate you so much. Just go away and die
-----------------
[31/Dec/2020:09:19:17] Wtf
-----------------
[31/Dec/2020:06:16:58] Wow ThaT's intersting, and also I think you're a heretic.
-----------------
[31/Dec/2020:05:04:05] Pogo
-----------------
[31/Dec/2020:04:48:40] bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
-----------------
[31/Dec/2020:03:54:25] kawww kawwww kawwww ~ Crow.
-----------------
[31/Dec/2020:02:16:02] Leave a comment
-----------------
[31/Dec/2020:01:21:55] very cool if true.
-----------------
30/Dec/2020:23:21:02 | wddddd
-----------------
30/Dec/2020:22:36:46 | Test
-----------------
30/Dec/2020:21:04:50 | Test
-----------------
30/Dec/2020:20:44:11 | Interesting
-----------------
First successful comment from the Crow - Aw yeah!
-----------------