Not so long ago I decided I want to redo the way my website is generated. For a long time already I've been thinking of making my own HTML templating system, coming up with different ideas, and never implementing them. So, I finally got around to doing it. After 3 days of almost non-stop work exclusively on this one project, I had a working prototype of what I named Durak (after the Russian word дурак meaning fool) — an HTML templating system for static site generation.
I decided implementing a parser from scratch on my own would be too time-consuming, so with some prior experience I chose to use ANTLR, which is a parser generator. The way it works is you write a formal grammar of the language you want to parse, and rules for the lexer (aka tokenizer) that govern what is a token and when. You can use it to generate parsers in many different languages, including Java, Python and C++. I chose Python as I wanted to use the snake for scripting the static site generation in general. I'm quite happy with how the templating language syntax worked out, except for one mancament that I'm not really sure how to resolve. (You need to separate tag attributes with semicolons)
But how does durak help with maintaining a static website? What are its features? Well, there are a few main things that I wanted to achieve with it, and here is a list:
- Durak templates resemble HTML, with some opinionated changes made, such as the
closing tag always being
- The source directory structure maps 1:1 to the output's strucutre
- They are structured — unless you explicitly want to, you will not end up with an unclosed tag in the HMTL output without at least seeing a warning
- Code reuse is easily done with components
- There is first-class support for document metadata
- The model to be used for generation of a resource is just a
dictreturned by a function written in Python
Now, I'll not write an entire guide on how to use it here. (There is documentation and an example available on GitHub) But I will tell you the website you're reading right now is generated using Durak, which is most useful for auto-updating the article list and generating the RSS feed of the blog. (Yes, I finally have an RSS feed) So take that as a taste of its abilities. I can't see why you couldn't also use it for a tagging system on a blog, but I don't need, nor particularly want one for mine.