Skip to content

Instantly share code, notes, and snippets.



Last active Sep 21, 2017
What would you like to do?
Python script to create the file and YAML frontmatter for a Jekyll post
from slugify import slugify # this will have to be installed via pip
import subprocess
import time
blog_dir = "/home/you" # CHANGE THIS
blog_name = "blog" # CHANGE THIS
posts_dir = "/_posts"
# here you could override via command line but I'm lazy
title = raw_input("post title: ")
categories = raw_input("categories (space separated): ")
filename = "%s/%s%s/" % (blog_dir, blog_name, posts_dir, time.strftime("%Y-%m-%d"), slugify(title))
with open(filename, "a") as fp:
template = """---
layout: post
title: "{title}"
date: {date}
categories: {categories}
context = {
"title": title,
"date": time.strftime("%Y-%m-%d %H:%m:%S %z"),
"categories": categories
fp.write(template.format(**context))["vim", filename])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.