blogng/new_post.py
2019-01-29 14:29:28 -05:00

44 lines
922 B
Python
Executable File

#!/usr/local/bin/python3
import datetime
blog_title = input('title for the entry: ')
title_date = input('date for the entry (format:yyyy-mm-dd|defaults to today): ')
if not title_date:
title_date = datetime.datetime.strftime(datetime.datetime.now(),
'%Y-%m-%d')
tags = input('tags (space seperated): ')
filename = "{}-{}.markdown".format(
title_date,
'-'.join(blog_title.lower().split()))
'''
layout: post
title: "go: `:=` operator causes accidental shadowing"
date: 2016-01-14 21:13
comments: true
tags: tag1, tag2..
'''
metadata_fmt = """---
layout: post
title: "{}"
date: {}
comments: true
tags: {}
---
"""
metadata_fmt = metadata_fmt.format(
blog_title,
title_date,
', '.join(tags.split())
)
with open('blog/{}'.format(filename), 'w') as f:
f.write(metadata_fmt)
print("New entry {} is ready at {} for editing".format(
blog_title, filename,
))