import os
from pathlib import Path
from subprocess import run

posts = [post for topic in Path("./posts").iterdir() for post in topic.iterdir()]

config = Path(os.environ.get("PRES_CONFIG", "./configs/presenterm.yaml"))

out_dir = Path('./output')
out_dir.exists() or out_dir.mkdir()

for post_dir in posts:
    run_result = run([f"presenterm -e --config-file {config} {post_dir / f'{post_dir.name}.md'}"], shell = True)
    (post_dir / f'{post_dir.name}.pdf').replace(out_dir / f'{post_dir.name}.pdf')
