Home Archive Games Utils Paintings About Contact
April 9, 2018

Generating static web pages

I just finished updating this site a bit, making blog posts appear on the index page, generally making it more "bloggy". When I made the site I knew I did not want any comments section on the blog, so I figured I might as well generate the whole thing offline! This approach is quite minimalistic and requires little server-side infrastructure.

The generating is done using this Python script. It takes this template in which it finds where to inject the header and content. After that it scans this folder for .html-files from which the non-blog-post pages are generated.

The generating of blog posts is hard-wired to look inside the folder content/posts. Every file in there is then parsed, translating the minimalistic markup to HTML. So in order to make a blog post I just add a file to the content/posts folder, run the python script and upload the result to my server (which currently happens to be GitHub pages, since they freely serve static sites). The generation of blog posts also spits out the Archive page.

One funky thing I added was support for LaTeX markup (via KaTeX). This makes it possible to have fancy maths in the posts, making stuff such as this post about everything binomial possible. One thing I should do, but haven't, is to run the LaTeX generation offline as well, currently it is done using Javascript.

I think this setup has been very nice and it has opened my eyes to how often we overuse complicated dynamic websites and all the associated infrastructure.