Pelican is a free and open source static website generator. It takes a collection of files written in Markdown as its input, applies a theme and configuration, then outputs a full static website.
A static website is a collection of HTML and CSS files that don't need any database or back-end programming language. These websites can be hosted by any web-server regardless of language support.
While not necessary, its a really good idea to make a git project to source control your blog content.
The project will hold the configuration for Pelican, which defines the plugins, variables for the style-sheet, and the site name. This project also holds all the markdown files which make up the blog content.
The files should be placed in a structure as follows.
pelicanconf.py
file.content/posts
, and can be sorted into subdirectories.
The nested directory structure has no impact on how the site is rendered.content/pages
. These are handled specially by the
templating engine.content/images
stores image filesoutput/
doesn't need to exist here, but it's used by the -o
(output)
argument in Pelican as the directory to store the generated website files.
This directory should be ignored by Git..
+-- pelicanconf.py
+-- content/
| +-- posts/
| +-- first.md
| +-- how-this-site-works/
| +-- building-a-website.md
| +-- pages/
| +-- about.md
| +-- images/
| +-- pelican.png
+-- output/
The top of each post starts with some metadata that Pelican uses to scaffold the site.
title: Title of the post or page
summary: Detailed summary
slug: short-name-goes-in-the-url
category: whereThisWillBeSorted
tags: tag1, tag2
date: 2019-08-28
modified: 2019-08-28
status: published or draft
title
: defines the string at the top of the article and in the indexsummary
: used in the index pages. If not defined, a large and
somewhat ugly subset of the top part of your post will auto-populate this
field.slug
: defines the URL from which the post page is accessiblecategory
: place this post into a category, accessible from the sidebar in
this particular theme.tags
: a comma delimited list of indexed sub-categories. Can have many.date
: When the page was authoredmodified
: When the page was last changedstatus
: either published
or draft
. Defines whether the page is ready to
be displayed to the public.You can also define custom attributes to use in your themes. I've modified a theme to allow custom thumbnail files for the index and a blog image which look like this:
image: pelican.png
thumbnail: pelican-thumb.png
Regular text
# Big header (h1)
## Smaller Header (h2)
### Even smaller header
---
The numbers will automatically increment.
1. First item
1. Second item
1. Third Item
- First Item
- Second Item
- Nested List item with 4 spaces before the dash
- Third Item
Markdown files can also support raw HTML content, allowing you a lot of flexibility.
<table class="mytable>
<tr><th>Header</th></tr>
<tr><td>Cell</td></td></tr>
</table>
Linked text goes in square brackets the URL in round brackets.
[A web link](https://example.com)
![Alt Text](/images/blog_workflow.png)
The content is ready to be converted into a website. Use a Pelican container to generate the site. The pelican container can also act as a local web server to preview changes before pushing them.
Pull a pelican image from GCR or Docker Hub.
Mine is gcr.io/kylepericak/pelican
on GCR and kpericak/pelican
on Docker
Hub. The GCR image is private, since they charge me for the downloads.
docker pull gcr.io/kylepericak/pelican
# or
docker pull kpericak/pelican
Run this from the project root. It will mount the content/ and output/ directories into a new container named "pelican". It will also forward the port Pelican's web server listens on (8000) to the workstation's port 8888.
The Pelican auto-reload feature looks like maybe its multithreaded or something,
so running it as the root process of the docker container doesn't work.
Instead, launch the container with the tail -f /dev/null
command so it just
idles.
docker run -d \
--name pelican \
-v $(pwd)/content:/content \
-v $(pwd)/output:/output \
-p 8888:8000 \
gcr.io/kylepericak/pelican \
tail -f /dev/null
This will build the site files, launch the web server, and watch for new file changes so it can automatically rebuild.
The example docker exec
command runs interactively. I like to run it in a
dedicated tmux pane to show if anything has gone wrong.
docker exec -it pelican \
pelican \
-s /pelicanconf.py \
--debug \
--autoreload \
--listen \
/content \
-o /output
Now that the content is written, its time to host the static website on Google Cloud Storage.