Grumpy Gamer

Ye Olde Grumpy Gamer Blog. Est. 2004

Dec 30, 2025

When I started using Hugu for static site generation I lost the ability to have comments and we all know now supportive the Internet can be, so why wouldn’t you have comments?

I wrote a few php scripts that I added on to Hugo and I had comments again. I decided to store the comments as flat files so I didn’t complicate things by needing the bloated MySQL. I wanted to keep it as simple and fast as possible.

When a comment is added, my PHP script created a directory (if needed) for the post and saves the comment out as a .json file with name as the current time to make sorting easy.

When the blog page was displayed, these files (already sorted thanks to the filename) were loaded and displayed.

And it all worked well until it didn’t. Flat files are simple. but they can be hard to search or maintain if they need cleaning up or dealt with after a spam attack. I figured I use commandline tools to do all of that, but it’s a lot more cumbersome than I first thought.

I missed have them in a sql database.

I didn’t want to install MySQL again, but my site doesn’t get a lot of commenting traffic so I could use Sqlite instead. The downside is Sqlite write-locks the database while a write is happening. In my case it’s a fraction of a second and wouldn’t be a issue.

The second problem I had was the version of Ubuntu my server was using is 5 years old and some of the packages I wanted wouldn’t available for it. I tried to update Ubuntu and for reasons I don’t fully understand I couldn’t.

So I spun up a new server. Since grumpygamer.com is a statics site I only had to install Apache and I was off and running. Fun times.

But the comment flat files still bugged me and I thought I’d use this as an opportunity to convert over to Sqlite. PHP/Apache comes with Sqilte already installed, so that’s easy.

A long weekend and I rewrote the code to save comments and everything is back and working.

Given that a webserver and PHP already needed to be installed, it isn’t a big deal to use Sqlite. If you’re not comfortable with SQL, it might be harder but I like SQL.


Comments:

Fabio 2h ago
Nice!, i'm using MySQL since 2002 on my blog, so it's impossible to change for flat files with more than 180k comments and 9.5k posts 😅 but i'll always recommend using a database, you can avoid a lot of problems with this kind of situations and it's easier to clean after spambots, there's a lot of abstractions easy to add to any code so you don't have to write everything again, but it's a choice!
Lone Pirate 2h ago
Noice! Keep it simple, but not simpler!

If one doesn't like SQL but still wants an embeddedable database, I'd recommend lmdb.
Renão 2h ago
Honestly, I liked that first iteration with the files anyhow :)
It matches the simplistic design of a (file based) static website - but as you said, there are downsides and pitfalls.

In the end it feels like making tradeoffs to have this feature - but it's worth it in my opinion.

Getting feedback right at your blog posts by having something like comments or favs/likes/toots/... can be motivating to keep on writing.
Rando from activitypub 1h ago
Really cool!
Elaine Marley 19m ago
Be nice! Plain text only.

Add comment: