Static Blogging With Pelican

by Ostatic Staff - Jul. 02, 2013

The easiest way to write online might not be the best choice. If you are serious about building your online identity, putting your faith in a single companies platform puts you at risk of that company changing priorities, moving in a direction you no longer agree with, or just going away completely. The best way to go about building a site to last is to build it in a way that you can move it from place to place, server to server, with as little interruption as possible. This is what Pelican gives you, an open source tool that generates a static site you can upload to any server or cloud hosting provider.

Getting started with Pelican is fairly easy, especially if you are familiar with Python development. Pelican installs with either easy_install or the preferred method with pip, the documentation has a basic walkthrough that should get you up and running quickly. After installing, find a good place in your filesystem and run pelican-quickstart to generate a basic skeleton.

Once you have the basic skeleton, you will probably want to customize the themes a bit. The easiest way I found is to pick one of the themes in the online collection and start customizing it. Pelican uses the Jinja2 template engine internally, so the theme is built using a base.html file that is extended for each page and post created. The great thing about building Pelican themes is that they are all just HTML and CSS, with a bit of the Jinja2 syntax sprinkled about when appropriate.

To test the new theme, create a markdown file in the “content” directory, and populate it with a bit of metadata at the top of the file:

Title: Static Blog Publishing With Pelican
Date: 2013-07-02 09:34
Tags: opensource, blogging, pelican, python
Category: Tech
Slug: publishing-with-pelican
Author: Jon Buys
Summary: Pelican is a static site generator that lets you own your work.

Follow that up with the text of your post, using Markdown formatting, then save the file. To generate your site, run pelican from the top level of the project directory and Pelican will create the site in the “output” directory. Change directory into “output” and run python -m SimpleHTTPServer to start a basic web server running on port 8000 on your local machine. This lets you test out your formatting and make sure everything is looking as it should before uploading to the web. Once you are satisfied, it is a simple matter of rsync’ing the output directory to your hosting company.

Pelican takes a bit of work to setup, but the result is a highly portable presence that you can push to any available web server. Pelican should install cleanly on most modern Linux desktops, or you could run it on your server, depending on your setup and what you have available. Once you are satisfied with the process of generating your site and pushing it to the server, much of the drudgery of the process can be automated, freeing up more of your time for getting your ideas out of your head and into text.