Index · Archives · Atom

Install pelican on Ubuntu

Static blogs are all the rage now, and while setting up one of these is not as easy as registering an account on tumblr, it still isn't rocket surgery.

In addition to using the latest and greatest in publishing technology, you have the added benefit of not needing any executable code on your server. All the work — like generating the HTML files served later — is (or can be) done locally, on your own machine.

Since I like python, I decided to use pelican as generator, so the machine you want to use it on should have python installed. Their quickstart is actually pretty good, but since it doesn't cover using distribution-provided packages when available, I figured I'd document my approach here.

Let's get started. My machine runs Ubuntu 12.04, but most commands should work on any halfway recent linux installation, even though some paths might differ.

Setting up virtualenv

In order to not install any python eggs systemwide, we start by setting up a virtual environment for all of pelican's dependencies to live in.

  1. Install the needed programs

    sudo apt-get install python-virtualenv virtualenvwrapper
    
  2. Add those lines to your shell's resource file (e.g. ~/.bashrc) and rehash your shell (source ~/.bashrc should do the trick).

    export WORKON_HOME=$HOME/.virtualenvs
    source /etc/bash_completion.d/virtualenvwrapper
    
  3. Create a virtual environment for pelican and associate it with the directory your blog is stored (I will use ~/blog from now on).

    mkvirtualenv pelican
    mkdir ~/blog && cd $_
    setvirtualenvproject
    

Installing and initializing pelican

  1. Install pelican and, optionally, Markdown. I recommend using pip to do so.

    pip install pelican Markdown
    
  2. Initialize your blog by answering a few questions. Afterwards, you're done.

    pelican-quickstart
    
  3. In order to locally test your new blog, I recommend using python's builtin web server. pelican includes a script to automatically watch your content directory, building new files and serving them using said server. Unfortunately, this script didn't work out of the box on my machine. But don't worry, it's a rather trivial fix. Replace line 4 of the script with

    PELICAN=~/.virtualenvs/pelican/bin/pelican
    

    and line 7 with

    BASEDIR=${PWD}
    

Writing your first blog post

  1. More, you say? Alright then. Here's how to write your first blog post: Create a text file in ~/blog/content/. The name, depending if you're using reStructuredText or Markdown, should end with .rst or .md respectively. This small example should get you started.

    Title: My first blog post
    Date: 2012-9-11
    Tags: blog,post
    
    Everything but the title tag is optional, anything that's not a tag is turned into content.
    
  2. Let pelican do its magic and visit http://localhost:8000 afterwards.

    make html
    ./develop_server.sh start
    
  3. Upload the generated files (located in ~/blog/output) to a webserver of your choice — or let pelican handle that, too.

Useful resources

© drc. Built using Pelican. Theme by Giulio Fidente on github.