M - x MM z

Building a website with Babashka

After some experience creating blog posts with software offered by hosting providers or by generating websites from markdown, I felt it should be easier, more flexible, and more maintainable to create something simple like a website.

Dependency Hell

When I want to write a blog post ... I want to write a blog post! I don't want to 'negotiate' with broken dependencies, look for unclear, out-of-date or non-existent documentation, spin up containers or update container engines or remember conventions in supposedly simple configuration files.

babashka logo

Enter Babashka

In essence, Babashka is a tiny Clojure interpreter tuned for shell scripting. By compiling to a native binary using GraalVM, the infamous JVM startup times are GONE which makes the possibility of using Clojure on the command line a lot more attractive for a lot of Clojure enthusiasts.

Suddenly an idea struck: what if I could make a website with Babashka as only dependency? After all: installing and updating Babashka is very easy and Babashka is available on all platforms.

File organisation


The source code for my website can be found here. The directory listing already tells a lot about my development setup for this website.

The site folder contains my website pages as Clojure files, using the hiccup format. It also contains plain css files.

gen.clj is a Babashka executable that generates the html files from the Clojure files. It puts those html files together with the css files in the publish folder.

To publish, you just ./gen.clj that website into existence and 0.1 seconds later you can start pushing everything in the publish folder to your hosting provider.

Bells and whistles

That's all folks! That's all you need to build a website. You could even go more spartan and write the html yourself. That's a bit too bare-bones for me. I like an occasional helper function when it's needed. These helper functions are located in the tools folder.

Furthermore, I got tired of refreshing my browser after updating a blog post file in my editor, so I decided to create a dev.clj Babashka executable. It monitors my folders, runs the gen.clj script when it detects changes and then opens the refreshed page for me. It comes with the cost of an additional Babashka dependency: the filewatcher pod. For me that's worth it.


Although it's not perfect (yet!) I like this setup. It's all there in plain sight for me to adapt to my wishes. It's possible and even quite simple to add generated code from other ClojureScript projects of mine into this website. For instance, have a look at this Matrix Rain visualisation.

I'd like to thank Michiel Borkent for his awesome Babashka tool and for helping me getting this setup up-and-running. Building a website in Clojure has ever been easier (for me at least). If you decide to go this route as well, Michiel and I would love to hear about it!