Daniel Keast

Jekyll

programming

I have no need for dynamic content, and so much prefer the simplicity of having a static website. With a static site generator you can get some of the benefits of dynamic apps (automatically updated menus, avoiding duplication in markup) with much higher security and lower maintenance.

I’d written a tiny Python script to do the job years ago, using the Jinja templating engine. It was very barebones, but did what I needed:

#!/usr/bin/env python3

import shutil
import jinja2
import os

target = '/var/www/dan.kea.st'
env = jinja2.Environment(loader=jinja2.FileSystemLoader('.'))

files = [os.path.relpath(os.path.join(root, file), 'site')
         for root, dirs, files in os.walk('site')
         for file in files]

for file in files:
    src = os.path.join('site', file)
    dst = os.path.join(target, file)

    if '.html' in file:
        with open(dst, 'w') as f:
            f.write(env.get_template(src).render())
    else:
        try:
            os.makedirs(os.path.split(dst)[0])
        except FileExistsError:
            pass
        shutil.copy(src, dst)

Jekyll is a static site generator written in Ruby. It converts markdown documents (with a small yaml section at the top) into html pages which can be served by a standard HTTP server.

The benefit of Jekyll over my script is that it’s massively more powerful. It’s supports canned data structures, theming, sass etc. while also still being simple. It also allows me to write in markdown is much more comfortable than html and it’s angle brackets shifting off to the right all the time.

Jekyll is also packaged in Debian, which makes my life much easier since the tool will be installed in sensible places and kept up to date with it’s dependencies on my system.