Last active
December 21, 2015 00:40
-
-
Save kmonsoor/942d661b4666ddce352f to your computer and use it in GitHub Desktop.
Create a new MarkDown post for Pelican-generated blog
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
""" | |
author: Khaled Monsoor <[email protected]> | |
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