-
Notifications
You must be signed in to change notification settings - Fork 13
/
new-post
executable file
·69 lines (52 loc) · 1.29 KB
/
new-post
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
65
66
67
68
69
#!/usr/bin/python3
import sys
import datetime
import pathlib
import subprocess
title = sys.argv[1].title()
args = "".join(sys.argv[1:])
tags = []
tagwords = {
"py": "python",
"web": "webdev",
"blog": "blog",
"data": "data",
"bash": "bash",
"meta": "meta",
"aws": "aws",
"git": "git",
"docker": 'docker',
'help': 'help',
'discuss': 'discuss',
'sql': 'sql',
'javascript': 'javascript'
}
tags = [tagwords[tag] for tag in tagwords if tag in args.lower()]
slug = title.lower().replace(" ", "-").replace("_", "-")
frontmatter = f"""---
templateKey: blog-post
tags: {tags}
title: {title}
date: {datetime.date.today().strftime('%Y-%m-%dT%H:%M:%S')}
published: false
cover: "/static/{slug}.png"
---
"""
class PostExistsError(FileExistsError):
pass
directory = pathlib.Path(__file__).parent
path = pathlib.Path(f"{directory}/pages/blog/{slug}.md")
if path.exists():
raise PostExistsError(f"Post Already exists at {path}")
with open(path, "w+") as f:
f.write(frontmatter)
gadd = subprocess.Popen(
f'cd {directory} && git add {str(path).replace(str(directory) + "/", "")} ',
shell=True,
)
gadd.wait()
nvim = subprocess.Popen(
f'cd {directory} && nvim +12 +star {str(path).replace(str(directory) + "/", "")} ',
shell=True,
)
nvim.wait()