Home/Posts/Building a Blog With Haskell

Building a Blog With Haskell

Reflection on building a blog with Haskell

2023-12-2456 words

Context

For sometime now I’ve been a Haskell hobbyist tinkering with the language and exploring some of the mathematical foundations of the language. Most of the project I built so far were small side projects meant for my own learning. Most of them were incomplete and/or far from usable. For a long time I didn’t think I had the skill to build anything worth while with Haskell, but I decided to drop that mentality and ponder real projects I could build with the language. Since I was looking for a new job opportunity and a public dump for my thoughts, I decided to build a blog with Haskell.

Objective

The objective of this project was to build a blog with Haskell. I actually tried building one in the past with Hakyll, which I shamelessly deployed with the hopes of adding content later (and a proper domain). The issue was that I started getting caught up in UI animations and aesthetics, which trapped me in Javascript land with RxJS. The end result was a RAM hogging website that was far from useful. More importantly, I wanted to try building the static site generator myself rather than using Hakyll. This left me with the goal of building a basic blog that renders taggable articles written in markdown as html using Haskell.

Implementation

The project is a monorepo made up of 4 packages including development packages. The source code is available on GitHub

kskkido-blog

This package contains the core Haskell modules that build static HTML files from articles written in markdown. All the content on this website is generated by this package.

I explain the structure of the application in this post

kskkido-blog-assets

This package contains all assets (ie: Javascript, CSS, media) in the blog. All client side scripts are transpiled from Typescript using esbuild and the CSS files contain Tailwind CSS and a few custom classes. Planning to replace Typescript with Purescript for fun.

kskkido-blog-server

This package runs a very simple Haskell Servant server that distributes the HTML pages generated by kskkido-blog and kskkido-blog-assets as static content. This is solely for running the blog in my local environment.

kskkido-blog-infra

This package defines all the necessary AWS resources for the blog using AWS CDK. The blog is deployed to an AWS S3 Bucket, which sits behind Cloudfront with a sprinkle of Lambda Edge functions for routing.

Closing thoughts

This blog definitely took a lot longer to develop than using standard means, but I definitely learned a lot and for now I’m satisfied with what I have. I hope this project can be used as a reference for anyone interested in building something with Haskell.
As mentioned above, this source code of this project is available on GitHub.