assets/comments-on-jekyll.jpg

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.

pretty-sure-I-nicked-most-of-this-from-somewhere-else-too.png

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:

assets/jekyl-submitted-comments-loop.jpg

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.