Create a static blog with Pelican

Fri 14 March 2014

This is a quick tutorial on how to create a static blog with Pelican for my friend, Javed.

Background information

Generally when people mention blogs, it used to refer to popular blogging services like Wordpress, Blogger.com and so on. How these websites work is that they store all your blog posts as data on a database and query this database to display pages of your blog. However, a static blog is simply an HTML file (with some Javascript) and it is stored in a location. Github.com first offered the ability to display such HTML pages on user's github account at a URL: username.github.com if you had a user account at github.com/username.

Now other source code hosting services like Bitbucket also followed the trend and hence you see my blog! When you type in sindhus.bitbucket.org, your web browser queries bitbucket and bitbucket does its job by responding with a standard 201 HTTP code and follows it up by looking for a "index.html" file. If such a file is found then sindhus.bitbucket.org is loaded and the page that loads on your browser is index.html.

Now, Pelican is such a static blog generator that makes it easy for you to write blog posts without worrying about formatting, setting up HTML files, writing the blog's theme in Javascript/CSS and other such details. Pelican is written in Python and hence to use on your computer, you must install this software.

In Arch Linux, you can install it with these two steps:

  1. sudo pacman -S python2-pip

    Pip is a python package manager. A python package may be dependent on other python packages for it's correct working and pip manages installation of python packages for you.

  2. pip2 install --user pelican

    This tells pip to install Pelican just for you in your home folder. If you don't use --user, then you will require to use sudo to install pelican system-wide.

Create blog

To create a blog:

  1. Run pelican-quickstart and follow the instructions on the screen.

  2. After you have successfully created a blog, you can view it locally with:

  3. Run ls to check the new files created for you by step 1. You should see a file develop_server.sh, this script will run your blog locally for you. Run ./develop_server start and go to a browser, open http://localhost:8000.

  4. All the blog content will be in the folder called content. To add a new blog post, you create a new file with the format:

Title: Your title here
Slug: your-title-here
Date: 2014-03-14
Category:
Tags:

I personally recommend keeping separate folders for different categories and creating your blog posts in those folders. I don't use 'Tags' but you can use it if you want to.

Customizing configuration

After doing the ls, you will also see a file that was created automatically for you called pelican.conf and publishconf.py. You can customise the settings of your blog as per your choice. To know what you can customise, refer to the official documentation or even better is Terry Yu's post on How I setup Pelican

My pelican.conf is:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals

AUTHOR = u'Sindhu S'
SITENAME = u"Sindhu's blog"
SITEURL = 'http://sindhus.bitbucket.org'

TIMEZONE = 'Asia/Kolkata'

DEFAULT_LANG = u'en'

FEED_ALL_ATOM = 'feeds/all.atom.xml'
CATEGORY_FEED_ATOM = '%s.atom.xml'
TRANSLATION_FEED_ATOM = None
RELATIVE_URLS = True

LINKS =  (('Pinterest', 'http://pinterest.com/sindhus/likes/'),
          ('Movies', 'https://www.facebook.com/sindhu.sundar.in/movies'),
          ('Ohloh', 'http://ohloh.net/accounts/sindhus'),
          ('Goodreads', 'https://www.goodreads.com/user/show/8856323-sindhu'))

SOCIAL = (('Facebook', 'http://facebook.com/sindhu.sundar.in'),
          ('Twitter', 'http://twitter.com/sindhu'))

PLUGIN_PATH="/home/sindhu/code/blog/plugins"
PLUGINS = ['pelican_youtube']
THEME = "/home/sindhu/code/blog/themes/zurb-F5-basic"

DISQUS_SITENAME = "sindhus"

DEFAULT_PAGINATION = 8

USE_FOLDER_AS_CATEGORY = True
STATIC_PATHS = ['images', 'pdfs']

My publishconf.py is:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals

import os
import sys
sys.path.append(os.curdir)
from pelicanconf import *

SITEURL = 'http://sindhus.bitbucket.org'
RELATIVE_URLS = True

FEED_ALL_ATOM = 'feeds/all.atom.xml'
CATEGORY_FEED_ATOM = '%s.atom.xml'

DELETE_OUTPUT_DIRECTORY = False

DISQUS_SITENAME = "sindhus"

Disqus is a web service that will record comments of your blog readers for you. All you have to do is put your Disqus ID in your pelican blog. To see how it works, explore Disqus.com.

How to upload to github/bitbucket/provider?

Once you have created your blog on your computer, modified as per your liking, its time to put it on the Internet :-), the steps are:

  1. Create a repository with the name in the format of username.provider.org. For example, I have a repository with the name sindhus.bitbucket.org.
  2. In your computer, come to the folder called output where your blog was generated and create it to be a git repository with git init.
  3. In this output directory, run git add remote <name> <address>. You can find this in github towards the right handside of the page. Its the same address you would used to clone this created repository. Keep in mind, if you use the HTTP link, then you would have enter your password, if you use the SSH link, then you would have to configure your SSH keys with github or bitbucket.So for example, I would add git remote add bitbucket git@bitbucket.org:sindhus/sindhus.bitbucket.org.git.
  4. Now, you are ready to push your blog online with git push <name> <branch>. For example, I would do: git push bitbucket master.
  5. Once git pushes your work to the repository, your blog should be available online. So I after I upload I go to sindhus.bitbucket.org to check.

Category: Linux

comments


Debian MiniConf 2014

Wed 12 March 2014

This is my report/talk material for the upcoming Debian-MiniConf 2014. Due to lack of adequate time, I was unable to apply for a visa and hence am presenting remotely. These are my observations about newcomer experience with regards to packaging, getting to know the community in Debian and drawing ...

Category: Debian

comments

Read More

Learn programming in GNOME

Thu 06 March 2014

Whenever I have spoken about GNOME to students (GSoC and OPW aspirants), they have all had the same starting troubles and growing pains, "How to learn GTK+?!". To be very honest, I was learning it in a rather hacky way myself too, looking at existing code and going full on ...

Category: Internship

comments

Read More

FOSSASIA 2014 got it right!

Mon 03 March 2014

FOSSASIA 2014 just concluded in Phenom Penh, Cambodia and it was a delight to be present in the midst of all this amazing FOSS activity. I met some really cool people and learnt about projects that I will follow up on the coming days. Here are the things that FOSSASIA ...

Category: Internship

comments

Read More

FOSSASIA 2014

Sun 02 March 2014

Greetings from Phenom Penh, Cambodia! I am at FOSSAISA 2014 :-) It is an exciting event with people from many FOSS projects and the industry speaking about their communities, work and the opportunities it has for anybody who is interested. Google's Open Source Programs Office was present at FOSSASIA to ...

Category: Internship

comments

Read More

Now mentoring

Wed 19 February 2014

I have volunteered to mentor Documentation interns for the upcoming round of Outreach Program for Women :-) I am happy to teach and hopefully should be able to help aspirants realise their potential in the community bonding period. I am in +5:30 timezone and available on IRC as 'ingu' or ...

Category: Internship

comments

Read More

FOSS Portfolio pages

Sat 15 February 2014

I've been trying out a few FOSS projects to contribute to and when I apply to their events and hackfests it becomes verbose to have to link to all the contribution areas spread across git repositories, mailing lists and blog posts about previous events. So I made a page ...

Category: Internship

comments

Read More

Teaching GNOME Locally

Sat 15 February 2014

Since the end of my GSoC, whenever I've had the chance, I've given lightening talks, talks with code examples, slipped it in a conversation here and there - all about contributing to GNOME and trying out for GSoC and OPW at college. I've pitched to strangers I've ...

Category: Internship

comments

Read More
Page 1 of 13

Next »