Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Kelvin is a Python-based static website generator inspired by the beauty and simplicity of Jekyll
Python
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
kelvin
samples/test_site
.gitignore
.gitmodules
README.textile
kelvin.py

README.textile

Kelvin

Kelvin is a static website generator inspired by the beauty and simplicity of Jekyll. Kelvin allows you to write static websites using jinja2 templates, files and folders. Like Jekyll, Kelvin is also blog-aware, so you can structured blog entries that are organized by topic. I wrote Kelvin because I find jinja2 templates more intuitive than the Liquid templates used by Jekyll.

Usage

Kelvin steals a bunch of ideas from Jekyll. Kelvin operates on an input directory structure that looks similar to the following and produces a rendered website:

input:

  • _layouts
    • category.html (optional)
  • _posts
    • python
      • YYYY-MM-DD-article-title.html
    • category2
  • _extensions
  • about
    • index.html
  • index.html

output

  • YYYY
    • MM
      • DD
        • article-title.html
  • category (optionally output if a category template is included in layouts)
    • python
      • index.html
    • category2
      • index.html
  • about
    • index.html
  • index.html

The directories beginning with an underscore (“_”) all have special meaning, much like they do with Jekyll. The _layouts directory holds all of the templates. The _posts directory holds all of the categories and blog posts under each category. The _extensions directory allows for customization. You can do pretty much anything you want with extensions. On my site, I made a simple extension for creating a category page generator and a textile filter for my jinja2 templates.

The Kelvin engine will traverse through all folders/files on the site. For all posts and other regular files, it’ll look for a special metadata block beginning and ending with three dashes. Each of these files (pages) will be sent through the template engine. All other files, such as CSS, JavaScripts, or even non-template HTML files, will be copied to the output directory.

A sample Kelvin website that contains two blog posts, a home page and a simple Atom feed file is included with the project is.

Invoking Kelvin

Invoking Kelvin is very simple; it expects a source directory and an output directory. It’ll overwrite files as necessary in the output directory.

    myserver% kelvin.py [path to source] [path to output]
 

Page File Format

Below is an example page for Kelvin. It’s broken into two blocks: the YAML descriptor block (at the top) and the content block. The YAML descriptor block contains all the metadata for the page. Kelvin exposes all of these metadata attributes to the page template. The engine only interprets the layout attribute. If Kelvin encounters a page, but doesn’t find a layout property, it assumes the page itself IS the template. This is handy for producing an RSS template for example.


    ---
    layout: post.html
    title: My Cool Story
    blurb: "Here is a blurb that I've written."
    ---
    
    <h1>HTML Header</h1>
    
    <p>A simple paragraphy</p>
    
    etc.
    

Page Properties

The following properties are available to all pages.

  • layout: Kelvin will look for a template under the _layouts directory matching this name
  • body: This is the translated body after. It’s useful when using template inheritance.

Post Properties

Blog posts expose several other properties to templates in addition to the page properties:

  • url: The rendered URL relative to site root
  • date: The date of the post

Category Pages

Kelvin will render category archives if the site configures a category template. By default, Kelvin will look for a template called category.html and output all categories under /category/. If the template cannot be found, Kelvin will not output category archives. These settings can be overridden by creating a settings.py file in your site’s extension directory and defining the CATEGORY_TEMPLATE and/or CATEGORY_OUTPUTDIR properties.

Developing Against

It’s fairly straightforward to get setup using Kelvin. You’ll just need to grab the source from github and install its dependencies. Kelvin requires the following packages: pyyaml 3.09, Jinja2 2.4.1. You should be able to install both of these using pip.

    myserver% pip install pyyaml jinja2
 

License

(The MIT License)

Copyright © 2009 Jim Connell

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
‘Software’), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.