Obraz — static site generator in a single Python file mostly compatible with Jekyll

2012-06-02

Obraz 0.2 Released

This release introduces an experimental plugin system.

What's new:

Please note, that the plugin system is very experimental. It may be changed significantly in the future releases.

Having said that, let's see how to write plugins for Obraz. A plugin is a Python file sitting in the _plugins directory inside your site. This file will be sourced by Obraz before loading the site content.

A typical plugin should:

  1. Define some loading or processing functions
  2. Register these functions within Obraz

Let's create a simple plugin that automatically sets the layout of the blog posts to the posts_layout parameter value of _config.yml.

File _plugins/posts_layout.py:

def process_posts_layout(basedir, destdir, site):
    """Set default posts layout."""
    layout = site.get('posts_layout', 'post')
    for post in site.get('posts', []):
        post.setdefault('layout', layout)

obraz.processors.insert(0, process_posts_layout)

That's all you need. obraz is a special variable that refers to the Obraz module. You can see your plugin doing things in the output of Obraz:

$ obraz
Loaded 1 plugins
Loading source files...
Loaded 13 files
Set default posts layout...
Sort and interlink posts...
Generate pages with YAML front matter...
Copy static files...
Site generated successfully

Please refer to the source code of Obraz for more info. Remember that it's less than 500 lines!

Tags: release.