DEV Community

Raz
Raz

Posted on

How to create a static website using Pelican

This article was first published on razcodes.dev

Pelican is a static site generator written in Python. I decided to use it for my personal website and since this is the first post, I thought it would be very meta to document the experience.

The following steps were done on a Mac but they should work on other OSs maybe with minor modifications.

Setup

I have a folder in my user folder called 'www'. I created a folder in that folder for this project.

cd www
mkdir razcodes
cd razcodes

I have Python3 installed already on my computer so I created a virtual environment called 'venv' and activated the environment:

python3.8 -m venv venv
source ./venv/bin/activate

I installed Pelican in this new virtual environment following the instruction on their docs page.

pip install pelican[Markdown]

Starting the site locally

I ran the following command which creates the folder structure

pelican-quickstart

Following the instructions I added a new markdown file in the content folder that was created called hello-pelican.md

Title: Hello Pelican
Date: 2020-02-22 10:23
Category: General

This is the first post that I am writing in Pelican

Now it's time to generate the site and preview it

pelican content
pelican --listen

I opened the following url into your browser to see the page

http://localhost:8000/

Changes and final build

There are 2 files in the main folder that define the configuration.

  • pelicanconf.py
  • publishconf.py

The first one is for general configuration. You can change the links in the blogroll section, add your social links, change pagination and other things.

The second file is used for production configuration. It imports the previous file and then overwrites some settings.

You can create your own theme by creating a 'theme' folder and building it in there or by downloading one of the themes on Github.

After making all the changes and when you are ready for the final build, run the following command:

pelican content -s publishconf.py

Or you can use the following command if you have a custom theme:

pelican content -s publishconf.py -t theme

Here -t theme specifies the folder where the custom theme is located.

Once the build is done you can find the website in the 'output' folder.

Top comments (2)

Collapse
 
dexygen profile image
George Jempty

I think I'm going to try out Pelican, it seems much simpler than everything else.

Collapse
 
razcodes profile image
Raz

I think you totally should!