Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (41 sloc) 1.63 KB
layout title tags
post
Obraz 0.2 Released
release

This release introduces an experimental plugin system.

What's new:

  • Experimental plugin system
  • Compatibility with Python 2.6-3.2

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!