-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate.py
36 lines (31 loc) · 1.09 KB
/
create.py
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
from datetime import datetime
from pathlib import Path
from rich.prompt import Prompt, Confirm
from yaml import safe_dump
def main() -> None:
while True:
title: str = Prompt.ask("Title")
if title:
break
while True:
description: str = Prompt.ask("Description")
if description:
break
timestamp: str = Prompt.ask("Timestamp", default=datetime.now().isoformat())
prefix: str = timestamp[:4]
til: str = Confirm.ask("TIL")
slug: str = Prompt.ask("Slug", default=f"{timestamp[:7]}-{title.lower().replace(' ', '-')}")
data = {'published': True, 'description': description, 'date': timestamp, 'tags': []}
data['title'] = title
if til:
data['title'] = f"TIL: {title}"
slug = f"til-{slug}"
data['tags'] = ['TIL', ]
data["image"] = "/public/logos/til-1.png"
data["twitter_image"] = "/public/logos/til-1.png"
prefix = 'til'
path = Path(f"posts/{prefix}/{slug}.md")
text = f"---\n{safe_dump(data)}---\n"
path.write_text(text)
if __name__ == '__main__':
main()