Make a Pelican Blog

Kivan Polimis, Thu 24 March 2016, How-to

How to setup Pelican to build a blog with Travis-CI

The goal of this post is to use Pelican, a static-blogging Python package, and Travis-CI to automatically deploy a Github-hosted blog. Your blog's URL will be You will need Github and Travis-CI accounts.

I chose to use Pelican instead of other Python alternatives after reading this Jake Vanderplas post. These instructions are written for Linux-based operating systems (my computer uses Linux Mint) and some workarounds may be necessary if you have another operating system to install software.


  1. Create Github blog source repository
  2. Install Pelican
  3. Connect Github and Travis-CI
  4. Create Github blog repository
  5. Make first blog post
  6. Deploy Travis-CI

Create Github blog source repository

We will use two separate git repositories on Github for the source and the built website, let's first only create the repository for the source

Login to Github and create a repository named: <username> Initialize this repo with a so you can clone immediately. The <username> repository is the source repo for the Pelican blog.

Virtual Environment Blogging

I recommend creating a virtual environment to blog in for flexibility with Python package installations.

conda create -n blog python==3.5
source activate blog

Install Pelican

pip install pelican

Additional packages to install for website development

pip install markdown fabric beautifulsoup4 typogrify pillow webassets

Change directory to <username> folder

Run pelican-quickstart to set up the Pelican blogging platform. The screenshot below shows how to answer the quickstart questions to allow your blog to be hosted on Github.



Add requirements.txt for Pelican blog build on Travis

(echo pelican; echo markdown; echo fabric; echo beautifulsoup4; echo typogrify; echo pillow;
echo webassets) >> requirements.txt  

Create a .travis.yml file for Travis build

  - master
language: python
- 3.5
- pip install -r requirements.txt --use-mirrors
- make html
    on_success: always
    on_failure: always
after_success: bash
  - git config credential.helper "store --file=.git/credentials"
  - echo "https://${GH_TOKEN}" > .git/credentials

Connect Github and Travis-CI

In order to create the encrypted token, you can login to the Github web interface to get an Authentication Token, and then install the travis command line tool with:

Select your avatar in the top right of the screen
Select settings
Select Personal access tokens
Select generate new token near upper right of the screen
copy the token to a text editor

Select your avatar in the top right of the screen again
Select integrations
Select Travis CI
Add to github account and authorize application

In the web interface: Select your account name in the top right
Refresh and flick the repository switch on for your .io-src repository

On Ubuntu you need ruby dev to install travis

sudo apt-get install ruby1.9.1-dev
sudo gem install travis

Inside <username> repository:


The previous command leads to the folllowing prompt:
"detected repository as <username>, is this correct?"

type yes

Then create a script and update the global variable with yours:

#!/usr/bin/env bash

echo -e "Testing travis-encrypt"
echo -e "$VARNAME"

if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
    echo -e "Starting to deploy to Github Pages\n"
    if [ "$TRAVIS" == "true" ]; then
        git config --global "<user_email>"
        git config --global "<username>"
    #using token clone gh-pages branch
    git clone --quiet --branch=$BRANCH https://${GH_TOKEN}
    $TARGET_REPO built_website > /dev/null
    #go into directory and copy data we're interested in to that directory
    cd built_website
    rsync -rv --exclude=.git  ../$PELICAN_OUTPUT_FOLDER/* .
    #add, commit and push files
    git add -f .
    git commit -m "Travis build $TRAVIS_BUILD_NUMBER pushed to Github Pages"
    git push -fq origin $BRANCH > /dev/null
    echo -e "Deploy completed\n"

Create first commit for <username> repo

git pull origin master  
git status  
git add .  
git commit -m "initial commit"  
git push origin master

Create blog repository

Then we can create the repository that will host the actual blog: create the <username> repository for the website (initialize with for immediate cloning)

Make a post will not run without an initial post. Pelican blog posts can be written in markdown or reStructuredText.

cd content/

Post follow the following format:


See Pelican documentation for additional information on using Pelican to generate a static site.

After writing an initial post, use pelican command to generate a static html webpage

cd ..
pelican content

Preview your site locally before pushing and building on Travis
Other installation materials I've consulted suggest running the following commands in a new terminal.

cd <username>\output
python -m pelican.server

Your site is running locally at port 8000 http://localhost:8000/

Commit your first post to <username>

git status
git add .
git commit -m "added first post"
git push origin master

Run file to build your blog with Travis

chmod +x

Running sh creates the built_website folder that contains all website data, from .html pages to css stylesheets
I receive an access denied/authentication error the first time executes

Add your <username> repository as the origin in built_website folder

cd built_website
git remote add http<username>/<username>
git remote remove origin
git remote rename http origin
git remote -v

Github defaults to Jekyll, a Ruby package, to format static .html sites. Because our blog is formatted with Pelican, we need to add a .nojekyll file to ignore Jekyll defaults

touch .nojekyll
git add .nojekyll

Commit the .nojekyll file to your <username> repository

git commit -m "added .nojekyll file for formatting"
git push origin master

Commit the .nojekyll file and built_website folder to your <username> repository

cd ..
git status
git pull origin master
git add built_website
git commit -m "adding .nojekyll file and built_website folder"
git push origin master

now run to build your website on Travis


Your website is available at

Workflow for posts
- Write post as .md and place in content folder
- Run pelican content
- Add and commit new posts to <username> repository
- Use to automatically push <username> repository and build <username> website - Commit published posts from to <username> repository


  1. Pelican documentation
  2. notions and notes setup pelican blog post
  3. Automatically build pelican with Travis CI