Skip to content

Instantly share code, notes, and snippets.

@sleepdeprecation
Created December 22, 2011 00:27
Show Gist options
  • Save sleepdeprecation/1508353 to your computer and use it in GitHub Desktop.
Save sleepdeprecation/1508353 to your computer and use it in GitHub Desktop.
New Jekyll Post

This is a really simple python script to easily create a new post for Jekyll.

It takes one argument, the post name, and gives you a new file in your _posts directory.

To use it, call python new_post.py "name of post"

It will generate _posts/[year]/[month]/[year]-[month]-[day]-name-of-post.md, which will look like this:

---
title: [argument from call]
layout: [layout - it's a variable in the new_post file, set to default]
date: [current date and time in yyyy-mm-dd hh:mm:00 [timezone] format, timezone is another variable, set to -0600, or central time]
published: false
---

Pretty simple, but that's all that I really wanted.


Update 31 December 2011

I made a minor tweak, simply because I started noticing my _posts directory was getting a little unmanageable. The new version uses year and month folders to keep things a little more organized, and jekyll knows how that works, which is nice too.


Update 1 January 2012

Okay, so the last version didn't make directories if they didn't exist. It does now.

# new post
# setup some global things yourself...
timezone = "-0600"
layout = "default"
from sys import argv
import datetime, os
now = datetime.datetime.now()
dirn = "_posts/" + now.strftime("%Y/%m/")
if not os.path.exists(dirn):
os.makedirs(dirn)
filename = dirn + now.strftime("%Y-%m-%d") + "-" + argv[1].replace(" ", "-").lower() + ".md"
filecont = "---\ntitle: " + argv[1]
filecont += "\nlayout: " + layout
filecont += "\ndate: " + now.strftime("%Y-%m-%d %H:%M:00") + " " + timezone
filecont += "\npublished: false"
filecont += "\n---\n\n"
writer = open(filename, "w")
writer.write(filecont)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment