diff --git a/dennogumi_new_post.py b/dennogumi_new_post.py index 8109974..246818b 100755 --- a/dennogumi_new_post.py +++ b/dennogumi_new_post.py @@ -9,13 +9,18 @@ from subprocess import call import shutil from typing import List -from atomicwrites import atomic_write, AtomicWriter +from atomicwrites import atomic_write import frontmatter from git import Repo -import sarge +import pytz from slugify import slugify +import toml + POST_PATH = "content/post" +TEMPLATE_PATH = "archetypes/post.blank.md" +CONFIG = "config.toml" +TIMEZONE = pytz.timezone("Europe/Rome") def new_post_title(title: str) -> str: @@ -59,16 +64,14 @@ def create_post(post_title: str, tags: List[str] = None, print("hugo executable not found in PATH.") return - cmd = [hugo_cmd, "new", "-k", "posts", "--quiet"] title = new_post_title(post_title) path = Path(POST_PATH) / title - cmd.append(str(path)) - print(" ".join(cmd)) + shutil.copy(TEMPLATE_PATH, path) - pid = sarge.run(cmd) + with open(CONFIG) as handle: + site_config = toml.load(handle) - if pid.returncode != 0: - return + featured_image = site_config["params"]["featured_image"] header = frontmatter.load(path) @@ -80,6 +83,10 @@ def create_post(post_title: str, tags: List[str] = None, header["draft"] = draft header["comments"] = comments header["title"] = post_title + header["featured_image"] = featured_image + date = datetime.now(tz=TIMEZONE) + # '2021-01-09 02:14:57+01:00' + header["date"] = date.isoformat(timespec="seconds", sep=" ") frontmatter.dump(header, path)