Skip to content

Instantly share code, notes, and snippets.

@kmonsoor
Last active December 21, 2015 00:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmonsoor/942d661b4666ddce352f to your computer and use it in GitHub Desktop.
Save kmonsoor/942d661b4666ddce352f to your computer and use it in GitHub Desktop.
Create a new MarkDown post for Pelican-generated blog
"""
author: Khaled Monsoor <k@kmonsoor.com>
modified: 09-Dec-2015
license: The MIT License
"""
import sys
from datetime import datetime
MD_TEMPLATE = """
Title: {title}
Date: {year}-{month}-{day} {hour}:{minute}
Modified: {year}-{month}-{day} {hour}:{minute}
Category:
Tags:
Slug: {slug}
status: draft
Summary:
"""
def make_entry(title):
now = datetime.now()
slug = title.lower().strip().replace(' ', '-')
new_file = "content/articles/{}{:0>2}{:0>2}-{}.md".format(now.year,
now.month,
now.day, slug)
MD_TEMPLATE = MD_TEMPLATE.strip().format(title=title,
year=now.year, month=now.month, day=now.day,
hour=now.hour, minute=now.minute,
slug=slug)
with open(new_file, 'w') as f:
f.write(MD_TEMPLATE)
print("New post file created as: " + new_file)
if __name__ == '__main__':
if len(sys.argv) > 1:
make_entry(sys.argv[1])
else:
print "No title given"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment