Index ¦ Archives ¦ Atom ¦ RSS

Playing with Pelican

I spent one day trying to put this blog on Heroku. Googling on the web many authors explain how to create a static site on Heroku, and Pelican web site offer a ready to use buildpack.

Anyway I did not like any of these solutions as all of them seem recompile and install the full stack (nginx, pelican, python....)

I moved to a more pratical and easy to implement solution: GitHub pages and Pelican.

Install Pelican

To install Pelican and other Python package dependencies in a virtual environment, I followed the instructions in the official Pelican documentation.

pip install pelican Markdown typogrify

I enabled article pagination so that I didn't end up with all the posts on a single page. The Makefile is incredibly useful, so I enabled that. It allows you to compile the website with make html and check it live with make serve.

Because I want to use Github pages I answered NO to all the questions about Dropbox, S3, FTP and SSH anyway the related code is still in the Makefile so I removed it manually.

Configure plugins

To configure plugins simply clone pelican-plugins as git submodule with

git add submodule
git submodule update  --init --recursive

and enable what you like in

    PLUGIN_PATHS = ['pelican-plugins']
    PLUGINS = ['interlinks',

Configure Github

For Github you need to put the domain of your site inside a CNAME (must be uppercase) file at the root of your site.

More details how to configure your domain can be found here (Tip #2), here and here

For my configuration I used


    STATIC_PATHS = ['images', 'extras/README.rst', 'extras/CNAME', 

        'extras/README.rst': {'path': 'README.rst'},
        'extras/CNAME': {'path': 'CNAME'},
        'extras/robots.txt': {'path': 'robots.txt'},

Minor improvements

Get metadata from path

To store articles in a structure like category/YEAR/MONTH/DAY-slug so I updated my as

   PATH_METADATA = '\A(?P<category>[^/]+)/(?P<date>\d{4}/\d{2}/\d{2})-(?P<slug>.*)(.md|.rst)'

You can always override date, slug and category in your post.

Serve file with different path

To serve your articles with url like /YEAR/MONTH/DAY/slug.html

    ARTICLE_URL = '{date:%Y}/{date:%m}/{date:%d}/{slug}.html'
    ARTICLE_SAVE_AS = '{date:%Y}/{date:%m}/{date:%d}/{slug}.html'

You must set both the setting.

you can see the result here

© 2014 Stefano Apostolico. Built using Pelican. Member of the Internet Defense League.