From 27a8165761bcdc2d8ca1bed1fc1bf96931b4bd1d Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Sun, 10 Jan 2021 14:50:59 +0100 Subject: [PATCH] Use the suffix so that the file is actually highlighted correctly --- dennogumi_new_post.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dennogumi_new_post.py b/dennogumi_new_post.py index a93ea3f..8109974 100755 --- a/dennogumi_new_post.py +++ b/dennogumi_new_post.py @@ -6,9 +6,10 @@ import argparse from datetime import datetime from pathlib import Path from subprocess import call +import shutil from typing import List -from atomicwrites import atomic_write +from atomicwrites import atomic_write, AtomicWriter import frontmatter from git import Repo import sarge @@ -36,7 +37,8 @@ def commit_initial_post(post_title: str, post_filename: str): def edit_post(post_path): with post_path.open() as handle: - with atomic_write(str(post_path), overwrite=True) as writer: + with atomic_write(str(post_path), overwrite=True, + suffix=".md") as writer: writer.write(handle.read()) writer.write("\n\n") writer.flush() @@ -50,10 +52,18 @@ def create_post(post_title: str, tags: List[str] = None, categories: List[str] = None, comments: bool = True, draft: bool = True) -> Path or None: - cmd = ["hugo", "new", "-k", "posts", "--quiet"] + + hugo_cmd = shutil.which("hugo") + + if hugo_cmd is 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)) pid = sarge.run(cmd)