new script to generate blog entries
This commit is contained in:
parent
92ab27a0f9
commit
d264053e82
10
blog/2017-08-02-hello-world.markdown
Normal file
10
blog/2017-08-02-hello-world.markdown
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
layout: post
|
||||
title: "hello world"
|
||||
date: 2017-08-02
|
||||
comments: true
|
||||
categories:
|
||||
- script
|
||||
---
|
||||
|
||||
well, lets see how you compule
|
50
new_post.py
Executable file
50
new_post.py
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
import datetime
|
||||
import yaml
|
||||
|
||||
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
|
||||
categories:
|
||||
- go
|
||||
'''
|
||||
metadata_fmt = """---
|
||||
layout: post
|
||||
title: "{}"
|
||||
date: {}
|
||||
comments: true
|
||||
categories:
|
||||
{}
|
||||
---
|
||||
"""
|
||||
catblock = " - {}"
|
||||
cats = map(catblock.format, tags.split())
|
||||
|
||||
|
||||
metadata_fmt = metadata_fmt.format(
|
||||
blog_title,
|
||||
title_date,
|
||||
'\n'.join(cats)
|
||||
)
|
||||
|
||||
with open('blog/{}'.format(filename), 'w') as f:
|
||||
f.write(metadata_fmt)
|
||||
|
||||
print("New entry {} is ready at {} for editing".format(
|
||||
blog_title, filename,
|
||||
))
|
Loading…
Reference in New Issue
Block a user