Home > Programming > Building a static site generator (ssg)
published 2021-02-21
Why would I want to write my own static site generator? Well, because this should
be a simple task, it should be fun, and I could make use of my recently aquired Rust knowledge.
Oh and sorts like Hugo are pure overkill for something like my little text site. Remember, feature bloat eventually makes every software project unmaintainable. KISS all the way!
But why would I need a ssg in the first place, can't I just write pure HTML and CSS? Well yes I could,
but after like 5 pages making even small changes to the style or markup etc. becomes a cumbersome nightmare (search and replace only gets you so far). Oh and don't even try to change the structure after you wrote some fancy articles, you'll end in Hell's kitchen.
Also with the standard approach of separating markup from actual content makes things easier in the long run (separation of concerns is always a good idea). And I love markdown!
The feature list for such a simple tool is really short:
- Convert content files from markdown to html with the help of html templates
- Support for minimal site structure
- Define html templates in extra files
- Define the theme in one simple css file
- Support for static assets (images, download files etc.)
- built-in http server for fast turn-around in development
After reading up on the first two bullet points of the above list, I noticed that in order to make these features I would need some sort of template engine with a template language which supports variables, control structures (if, foreach etc) ... you get the point. Further search on the topic of template engines immediatly brings Django and Jinja2 to the table. Or Tera! And this lead me to Zola!
Zola is a small static site generator written in Rust, which uses the lightweight template engine Tera bundled into a single binary program. No dependencies, super fast, easy to use, flexible? Count me in! Having read the getting started guide and just using all within it in like 30 minutes, I was hooked. This is exactly what I needed. No feature bloat, super fast result. Two hours later my blog was rebuild from the ground up to serve the same content as before, but with Markdown instead of Html and a lot more flexibility.
This is where the research to build my own static site generator stopped, I just found the perfect tool for my tech blog. I am a bit sad about this cause I really would have fun doing it myself, but this was not the right place to do it myself when (nearly) perfect solutions exist.