cjkinnilight

A simple static site generator in Elixir

Inspired in large part by Conor Hoekstra, I've been getting more into functional programming over the past few months. I've been consuming a lot of functional programming content, and tryign to work more pure functions into my programming, but until this week, I haven't spent much time doing development in a functional language.

This week, I've built two working things in Elixir.

First, there's a proxy server to assist me in developing against heavily ratelimited APIs. It's using Phoenix, and I had it up in running from never having written a line of Elixir in about six hours (much of which was spent navigating RFCs to make sure I completely understood how HTTP and HTTPs proxies work.)

Second, is the little tool I'm using to generate this site. It's basically a MVP static-site generator. That is, it takes a folder of Markdown formatted documents and spits out a table of context and some nicely formatted blog posts. Eventually I'll add an Atom feed, and maybe some other nice features. This was an evening project today, and it took about two hours while watching TV with Laura. It's very janky, but it's also very simple, which I like.

It basically consists of a few files:

/lib/blog_engine.ex:

This consists of nine simple helper functions that do various things like delete all the files in a directory, get a directory list, parse a blogpost, and render the templates. There are some hardcoded paths I'd like to move out of the tool, but I think it's fine for now.

/build.ex:

This is where the magic happens. It's almost exclusively written using the |> pipe operator, and passing lists through a bunch of functions that do the real work. I'm not sure this is ideal, but it's really simple to think about composing these little functions like this. It deletes the last version of the site, re-generates from the source files, and replaces any deleted static files I want.

/generate.sh:

This runs /build.ex, then commits changes to both my BlogEngine repository and the repository that runs CJKinni.com, so that the changes will go live on CJKinni.com within a few minutes.

I enjoyed writing the code. It's very straightforward, and I think that it will be easier to return to than some of the other coding projects I've taken breaks from.

I'm still not sure what the result of my deep dive into category theory will be, but for now I'm enjoying the ride.