Add inv new-task

This commit is contained in:
Tyrel Souza 2022-10-17 13:15:08 -04:00
parent f37a836ae4
commit b8db611c29
No known key found for this signature in database
GPG Key ID: F6582CF1308A2360
2 changed files with 32 additions and 1 deletions

View File

@ -19,3 +19,5 @@ sgmllib3k==1.0.0
six==1.16.0
soupsieve==2.3.2.post1
Unidecode==1.3.6
python-slugify

View File

@ -141,3 +141,32 @@ def publish(c):
def pelican_run(cmd):
cmd += ' ' + program.core.remainder # allows to pass-through args to pelican
pelican_main(shlex.split(cmd))
@task
def new_post(c):
import os
from slugify import slugify
iso_date = datetime.datetime.today().strftime('%Y-%m-%d')
year, month, day = iso_date.split("-")
title = input("Title: ")
slug = slugify(title)
filename = f"{iso_date}_{slug}.rst"
title_header = "#" * len(title)
template = f"""{title}
{title_header}
:date: {datetime.datetime.today().strftime('%Y-%m-%d %H:%M')}
:author: tyrel
:category: ????
:tags: ????
:slug: {slug}
:status: draft
"""
base = f"content/blog/{year}/{month}"
os.makedirs(os.path.dirname(base), exist_ok=True)
with open(f"{base}/{filename}", "w") as f:
f.write(template)
print(f"Wrote: {base}/{filename}")