Add inv new-task
This commit is contained in:
parent
f37a836ae4
commit
b8db611c29
@ -19,3 +19,5 @@ sgmllib3k==1.0.0
|
|||||||
six==1.16.0
|
six==1.16.0
|
||||||
soupsieve==2.3.2.post1
|
soupsieve==2.3.2.post1
|
||||||
Unidecode==1.3.6
|
Unidecode==1.3.6
|
||||||
|
|
||||||
|
python-slugify
|
||||||
|
29
tasks.py
29
tasks.py
@ -141,3 +141,32 @@ def publish(c):
|
|||||||
def pelican_run(cmd):
|
def pelican_run(cmd):
|
||||||
cmd += ' ' + program.core.remainder # allows to pass-through args to pelican
|
cmd += ' ' + program.core.remainder # allows to pass-through args to pelican
|
||||||
pelican_main(shlex.split(cmd))
|
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}")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user