Html generator

#projects #rust #web

This project was really the precursor to this very website, back when it was but a twinkle in my eye.

My general motivation for this was that I was begining to want to set up a personal site, and as I wanted to be able to write blogs, I would probably need some kind of templating engine.

My main problem was that most popular templating engines all require pulling in a large codebase, and learning some new esoteric format, all to support features that I don't necassarily care for.

As such, given the simplicity of the problem, I thought it would be a nice initial project to cut my teeth on while learning Rust. For bonus points, as the structure of this project was fairly straightforward, and I could plan it clearly in adavance, I also decided to try out use this project to evaluate the merits of literate programming for my personal projects, and as such wrote the entire project as a single literate program.

Overall the project turned out quite well, and I found that literate programming was quite a nice way to make the codebase easy to approach. My only complaint with literate programming would be that it made refactoring and changing the structure of the program quite difficult, as any large structural changes would also necessitate changing a lot of the surrounding text to preserve coherency.

The generator works using two kinds of files - template files and source files.

Template files encode the base HTML of your site, including placeholders that will be instantiated by the source files:


The source files the provide values for these placeholders - to simply the substitution process (yes it's a cheat) I ended using the negation symbol to delineate elements, rather than trying the parse html manually.

#+template blog/
title: A statically generated site without any JS¬
    I built this site <b>without</b> any JS baby.
    I can put divs <div>within this templated content</div>
    without issue¬
<link ref="" name="style" />¬

You can find the project here: html-gen