kaashif's blog

Programming, software freedom and Unix

Converting my blog to frog

What is frog?

Frog is a static website generator written in Racket. It does the same sort of thing as Jekyll, Hakyll and other software like that, some of which I’ve used in the past.

What does “frog” mean?

There’s a simple answer to this on their README:

Q: “Frog”? A: Frozen blog.

I’m not 100% on what that means exactly, but the program works great, so who am I to say that their name doesn’t make sense?

What this blog post isn’t

They have some really great documentation on how to get started using frog and I’m not trying to write a blog post replicating all of their effort.

What I really want to focus on is how I converted my Hakyll website into a frog site.

Converting all of my posts into the frog format

The bulk of the work was going to be converting all of the metadata I had from the Hakyll/Jekyll style:

title: My Post Title
date: 1970-01-01
comment: something witty

into the frog format, which doesn’t have a comment field (I added that on top of Hakyll’s default config myself anyway), but does have a tags field and looks like this:

    Title: My Post Title
    Date: 1970-01-01T00:00:00

So the header at the top of every file had to change almost completely. Let’s think, what tool can we use to go through a load of files and transform each line based on a series of regexes and maybe something more complicated?

That’s right, I wrote a Perl script!

The aim of this exercise is just to come up with a script where I can do ./myscript.pl post and it’ll output the changed post, so that I can then just use sponge to overwrite the post itself.

(If you don’t know about sponge, it’s a really cool program for when you want to do something to a file in-place, you can’t be bothered with a temporary file, and the program you’re using doesn’t support in place operations, install it! It’s usually in the package moreutils on most distros, or at least it is on Debian.

Writing the script

It’s a pretty standard script to be honest, since this is what Perl is built for, processing text. Also, there’s a long tradition of sysadmins whipping up quick Perl scripts to do things, since Perl is everywhere.

I wrote the following in script.pl.

use strict;
use warnings;

my $fname = $ARGV[0];
open(my $file, "<", $fname);

while (my $line = <$file>) {
	if ($line =~ /^---$/) {
	} elsif ($line =~ /^title:/) {
		my $title = ($line =~ s/title: //r);
		print "    Title: $title";
	} elsif ($line =~ /^date:/) {
		my $date = ($line =~ s/date: //r =~ s/\R//r);
		print "    Date: ${date}T00:00:00\n";
	print $line;

I don’t know if that warrants much explanation, really, it’s an easy to understand script. I made sure not to use $_, since invisible variables really frighten me.

Anyway after that, I just typed something into the shell:

for f in *.md; do
	./script.pl $f | sponge $f

And that was that, all of my posts were now frog.

That’s essentially it

Everything else worked as I’d expect, I just needed to convert my templates to frog’s style, which is really Racket’s style, and that was very easy, since I kept barely any of the logic of my site in the templates.

Well, uh, there’s not much more to say. Really, using frog is that easy, I’d really recommend you use it if your current blogging platform is giving you trouble.

Happy frogging!