ref: deploy-2019-10-30 blogng/new_post.py -rwxr-xr-x 922 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/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,
))