some reworking

This commit is contained in:
SG
2025-06-07 13:17:51 +03:00
parent fc1ee27146
commit 1854366a9d
7 changed files with 183 additions and 74 deletions

42
functions.py Normal file
View File

@@ -0,0 +1,42 @@
import os, subprocess
import shutil
from pathlib import Path
from classes import DefaultFrontmatterHeader
from config import Config
from logger import logger
def create_content(filename):
filename += '.md'
filename = Path(f"{Config.CONTENT_DIR}/{filename}")
if not filename.exists():
fh = DefaultFrontmatterHeader(filename.stem)
logger.debug(f"Creating new content {filename}")
with filename.open("w", encoding="utf-8") as f:
f.writelines(['---\n', fh.title, fh.date, fh.description, fh.author, fh.omit_second_title, '---\n', '\n', '\n'])
def edit_content(filename):
logger.debug(f"Editing content {filename}")
editor = os.environ.get('EDITOR', 'vim')
subprocess.call([editor, filename])
def init_site():
logger.debug(f"Initializing new site")
# Recreate output directory if necessary
output_dir = Path(Config.OUTPUT_DIR)
if output_dir.exists():
shutil.rmtree(output_dir)
output_dir.mkdir()
# Create output directory subtree
for dir in [ Path(Config.CONTENT_DIR), Path(Config.STATIC_DIR), Path(Config.TEMPLATE_DIR),
Path(Config.OUTPUT_IMG_DIR), Path(Config.OUTPUT_CSS_DIR), Path(Config.OUTPUT_JS_DIR)]:
dir.mkdir(exist_ok=True)
# Create "About.md" content item
create_content("about")
def build_site():
logger.debug(f"Starting build")