An Example Pelican + Git Blog Post Workflow

On my Windows subsystem for Linux environment, I am now publishing new blog posts following this Pelican-based workflow:

1. Activate the Python environment: cd Your_Env/bin & source activate
2. Go to the project folder: cd /home/username/my_project
3. Run Python script to create new markdown file from a template:
python new_post.py
4. After writing the new post, update the Pelican content:
pelican content

(Optional) preview the new post at local host http://127.0.0.1:8000/
pelican -l 
5. Use git to stage, commit and push the files to a Github repo:
git add .
git commit -m "new post edits and fixes"
git push -u origin main

The new blog post is now live! This is my own workflow for my Pelican blog, divbull.com, which is hosted for free with Cloudflare Pages. You can read more about connecting Pelican and Cloudflare in this past post I wrote.

You will need to create a SSH key and connect it to your Github account to get this completely working, as it’s required by Github now. Make sure you write down your passphrase! I was able to create an ssh key with this command:

ssh-keygen -t ed25519 -C "youname@example.com"

Below is the short Python script I wrote for generating the markdown file for a new post. I’ve enjoyed working this out on my new blog and now can fire off posts rapidly with this command line based workflow.

from datetime import date


def post_name():
    """Ask for the new post's name."""
    name = input("Enter the new post's title:\n")
    return name


def post_template(title):
    """Return str, post draft"""
    post = f"Title: {title} \nDate: {date.today()} 4:20 \nCategory: Essay"
    return post


def save_draft(name, post):
    """Save new post draft to content folder."""
    content = "/home/erickbytes/divbull/divbull.com/content"
    name = name.replace(" ", "-")
    md = f"{content}/{name}.md"
    with open(md, "w") as fhand:
        fhand.write(post)
    return None


name = post_name()
post = post_template(name)
save_draft(name, post)