Build a blog using Pelican

Posted on Mon 12 December 2016 in Technical

logo

What is Pelican?

Pelican is a Static Site Generator powered by Python. Pelican is written in Python and it doesn't need any database or server side programming. Simply we can write the content of the webpage and run pelican server to view the page containing the content. It is simmple and easy to use to publish your content.

Get Pelican

Pelican is written in Python and hence the python need to be installed in your machine. Most of the GNU/Linux distros will have python.

To check the availability of python in your machine, open terminal and type the following command

python --version

If python was not installed, Click Here!.

After installing python and necessary packages, install pelican using the following command

sudo pip install pelican

And thus pelican will be installed in your machine.

Getting Started with Pelican

Once you installed pelican in your machine, get started using the following.

Make a new directory with the site name by the command mkdir folder-name and enter into that directory by the command cd folder-name.

After entering into that directory type the following command

pelican-quickstart

Then terminal will prompt with few meaningful questions in simple english. You could answer to that questions once you read it. After answering all the questions, your outline of the website will be created.

Then type ls command to see the files generated by the pelican.

  1. content/
  2. developer.sh
  3. fabfile.py
  4. Makefile
  5. output/
  6. pelicanconf.py
  7. publishconf.py

Now you are containing the fresh site outline without any content.

To see the site, just follow the command.

sudo pelican content

This will make the content (if any) in the webpage.

and

cd output/

run the pelican server using the command,

python -m pelican.server

Your page will be server in localhost:8000

Writing the article or content

The article or a content may be written in reStructuredText text files or in markdown files.

Let me go with markdown file. These are the text files with the extension, .md

Before start writing your article or content, you may need to install markdown.

To install markdown,

pip install Markdown

After installing Markdown, install typogrify

pip install typogrify

Once all finished, start writing your first awesome article.

  1. You can shift to the content directory using cd content
  2. Open a new file with filename article_name.md
  3. The structure of the file should be
Title: (Title of your article)
Date: (Date)
Category: (any catogory such as post) 

Your writings

If you want to learn Markdown, Click Here

Generate your site

Once you add your article in content directory, get back to the site directory by using cd .. and follow the command

sudo pelican content

This will make your site with the articles in the content folder. After that run the pelcian server by the following

  1. cd output/
  2. python -m pelican.server

Thus your site will be generated and served in localhost:8000

Installing themes in Pelican

Feeling bored with default theme. Have a attractive themes as you like.

Click Here to get themes.

Once you downloaded the zip file of the themes, just extract it somewhere.

To install the themes in pelican

pelican-themes -i (path where the themes is extracted)

Example

pelican-themes -i /Documents/themes/clean-blog

Once the theme is installed, You can apply the theme into your site or blog by the following.

  1. Open the pelicanconf.py file
  2. Add THEME = "theme name" anywhere in that file
  3. Save and close the file.

Thus the theme is applied in your blog.

To see, Just pelican content, run the server and open localhost:8000

Note: You can edit the theme by editing the html files in the theme folder.