Building your own static website has several advantages over a traditional website that uses a database to store content. Static websites are faster because pages are rendered in advance and deliver the same content to all visitors. They are cheaper to host and are more secure since the website has no database.

Creating each page in a static website one-by-one and updating them when something changes would be very time consuming. Static site generators take a website's content, apply it to HTML-based templates and generate all of the required files ready-to-upload. There are many static website generators available on the web, but i chose Pelican because of my preference for Python.

This tutorial is part of a series which will walkthrough all the steps from installing Pelican to deployment on Bitcuket.io pages (for free). I decided to create these tutorials after making my own website with Pelican.

Goals:

  • [x] Install Pelican
  • [x] Generate a static website
  • [x] Creating A Project Skeleton

Let's begin by creating a new folder called blog with two subfolders inside the blog folder called output and source as shown below. Our Pelican project will be stored in the source folder. The static website generated by Pelican will be placed in the output folder.

blog
  └── output (folder)
  └── source (folder)

Next we need to install Pelican and Markdown. Markdown is a plain-text markup language we will be using to write the content for our website.

pip install pelican
pip install markdown

With our basic file structure in-place and Pelican/Markdown installed we are now ready to create our Pelican project. Navigate to the source folder using the command line and type:

pelican-quickstart

Pelican starts by asking us a series of interview questions to customize our website. After answering the pelican-quickstart interview questions your source folder will look like this:

blog
  ├── output
  └── source
       ├── content (folder)
       ├── output (folder)
       ├── pelicanconf.py
       └── publishconf.py

Here's what each of the newly created files do: * content (folder) - where website content will be stored * output (folder) - default location where static website files are generated to * pelicanconf.py - website settings file * publishconf.py - additional website settings used only when the website is published

Now that our basic project skeleton is setup we should generate our website and preview what it looks like. First, we must tell Pelican which folder to output the website to. By default it will be generated to blog/source/output but we wanted them to appear in blog/output instead. Delete the folder blog/source/output. Now open pelicanconf.py and add the following line:

OUTPUT_PATH = '../output'

Generate the website by using the following command while in the source folder. Ignore the warning that appears. It displays because we haven't written any articles for our website yet:

pelican content

Finally, run the following command while in the source folder. It will setup an http server on our local machine that will allow us to preview the website.

pelican --listen

To view our website open your web browser and go to the the address: http://127.0.0.1:8000.

We have now successfully setup our basic Pelican project.


Comments

comments powered by Disqus