June 17th, 2018 (back)

Designing a Static Blog

I really enjoy a simple site. Throw in some static content generation, a bit of CSS, maybe a hint of JavaScript if you need it. Otherwise, just keep it simple and easy to read.

A Simple Blog

Here is the source for generating this blog. It's incredibly simple static generator.

import htmlmin
from jinja2 import Environment, PackageLoader

env = Environment(
    loader=PackageLoader('blog', 'templates')
)

posts = [{'date_short': '2018-06-17',
          'date_long': 'June 17th, 2018',
          'title': 'A Simple Blog'}]

article = env.get_template('article.html')
navigation = env.get_template('navigation.html')
for post in posts:
    rendered = env.get_template(post['date_short'] + '.html').render()
    post['content'] = rendered
    with open('articles/{}.html'.format(post['date_short']), 'w') as fd:
        fd.write(htmlmin.minify(input=article.render(post=post)))

with open('index.html', 'w') as fd:
    fd.write(htmlmin.minify(input=navigation.render(posts=posts)))

Here is what the directory layout looks like:

blog:
__init__.py  templates

blog/templates:
2018-06-17.html  2018-06-18.html  article.html  navigation.html
Not much to it. Just a simple Jinja2 template engine and a site generation. Write the posts in the make_blog.py and run it to generate new content.