1
0
Fork 0

Use the suffix so that the file is actually highlighted correctly

This commit is contained in:
Luca Beltrame 2021-01-10 14:50:59 +01:00
parent 0f07d72249
commit 27a8165761
Signed by: einar
GPG key ID: 4707F46E9EC72DEC

View file

@ -6,9 +6,10 @@ import argparse
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
from subprocess import call from subprocess import call
import shutil
from typing import List from typing import List
from atomicwrites import atomic_write from atomicwrites import atomic_write, AtomicWriter
import frontmatter import frontmatter
from git import Repo from git import Repo
import sarge import sarge
@ -36,7 +37,8 @@ def commit_initial_post(post_title: str, post_filename: str):
def edit_post(post_path): def edit_post(post_path):
with post_path.open() as handle: 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(handle.read())
writer.write("\n\n") writer.write("\n\n")
writer.flush() writer.flush()
@ -50,10 +52,18 @@ def create_post(post_title: str, tags: List[str] = None,
categories: List[str] = None, categories: List[str] = None,
comments: bool = True, comments: bool = True,
draft: bool = True) -> Path or None: 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) title = new_post_title(post_title)
path = Path(POST_PATH) / title path = Path(POST_PATH) / title
cmd.append(str(path)) cmd.append(str(path))
print(" ".join(cmd))
pid = sarge.run(cmd) pid = sarge.run(cmd)