Last active
September 21, 2017 18:14
-
-
Save Sigafoos/3adf25a94718d4edb0be4ffbe63cf639 to your computer and use it in GitHub Desktop.
Python script to create the file and YAML frontmatter for a Jekyll post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
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/%s-%s.md" % (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)) | |
subprocess.call(["vim", filename]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment