diff --git a/requirements.txt b/requirements.txt index 335af5c..755e7d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,5 @@ sgmllib3k==1.0.0 six==1.16.0 soupsieve==2.3.2.post1 Unidecode==1.3.6 + +python-slugify diff --git a/tasks.py b/tasks.py index 3eca4d4..d36edf5 100644 --- a/tasks.py +++ b/tasks.py @@ -140,4 +140,33 @@ def publish(c): def pelican_run(cmd): cmd += ' ' + program.core.remainder # allows to pass-through args to pelican - pelican_main(shlex.split(cmd)) \ No newline at end of file + 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}") + +