Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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