-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewpost.py
More file actions
executable file
·64 lines (56 loc) · 1.9 KB
/
newpost.py
File metadata and controls
executable file
·64 lines (56 loc) · 1.9 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
from __future__ import division, print_function
import argparse
import datetime
import os
import sys
import textwrap
from subprocess import call
def slugify(string):
import re
slug = re.sub(r'[^\w]+', '-', string)
slug = slug.lower()
return slug
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate a Pelican article template")
parser.add_argument('title', nargs='+')
parser.add_argument('-md', action='store_const', const=True, default=False)
parser.add_argument('--category', nargs="?", default='')
parser.add_argument('--tags', nargs="+", default='')
args = parser.parse_args()
num_articles = len(os.listdir('./content/articles'))
title = ' '.join(args.title)
date_string = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
slug = slugify(title)
if args.md:
header_string = """\
Title: {title}
Date: {date_string}
Category: {category}
Tags: {tags}
Author: Ashley Anderson
Summary:
Header_Cover: /images/piestewa_1024.jpg
"""
else:
header_string = """\
{title}
{title_bar}
:date: {date_string}
:category: {category}
:tags: {tags}
:author: Ashley Anderson
:summary:
:header_cover: /images/piestewa_1024.jpg
"""
header_string = textwrap.dedent(header_string)
header = header_string.format(title=title,
title_bar='#'*len(title),
date_string=date_string,
category=args.category,
tags=', '.join(args.tags))
fname = './content/articles/{:04d}-{}'.format(num_articles, slug)
fname = fname + ('.rst' if not args.md else '.md')
with open(fname, 'w') as new_article:
new_article.write(header)
call(['vim', fname])