Skip to content

Instantly share code, notes, and snippets.

@cz
Created May 4, 2014 04:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cz/5f8e58e76dfa9d0f8e3e to your computer and use it in GitHub Desktop.
Save cz/5f8e58e76dfa9d0f8e3e to your computer and use it in GitHub Desktop.

Cactus Blog Plugin

Setup

Enable the blog plugin by renaming blog.disabled.py to blog.py in your site's plugins directory.

Create a directory called posts in your site's pages directory.

Basic usage

Writing posts

Write posts by creating Markdown files (with the extension .md) in your posts directory.

Here's an example post:

title: Moving my Blog to Cactus
author: Johnny Dangerously
date: 2014-05-01
template: post.html

# Why I Decided to Switch

I think Cactus is a _really_ great tool and also cacti are prickly.

Dates can be either YYYY-MM-DD or DD-MM-YYYY.

Drafts

To keep an in-progress post from being published, simply add the following line to the post's header:

status: draft

Accessing post data in templates

Every page will have access to a master posts list, so you can loop over your posts anywhere:

{% for post in posts %}

Your post's template can access all of its metadata as variables:

<h1>{{ title }}</h1>
<p>by {{ author }}</p>
{{ body }}

You can add any metadata you want. So, for example, you could create a template that relies on cover images, and at the top of your posts just include:

cover-image: http://mycactusblog.s3.amazonaws.com/whatever.jpg

Then in your template you can just do:

<img src="{{ cover-image }}" alt="Whatever"/>

Configuration

You can customize your blog's path and set some default metadata for posts by adding a "blog" entry to your site's config.json:

"blog": {
    "path": "articles",
    "defaults": {
        "author": "Johnny Dangerously",
        "template": "post.html"
    }
}

The defaults will serve as fallbacks for missing values and can be overridden on a per-file basis.

URLs

Organize your markdown files however you'd like your posts to be accessed. If you want your posts to live at http://example.com/posts/2014/05/post-title.html, just use the following directory structure:

pages/
    posts/
        2014/
            05/
                post-title.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment