#!/usr/bin/env python3 """ 블로그 글 초안 자동 생성기. 사용법: python scripts/blog_automation.py "글 제목" python scripts/blog_automation.py # 대화형으로 제목 입력 생성 위치: content/posts/YYYY-MM-DD-slug.md 다음 단계(예시): - Cloudflare Pages는 보통 이 repo를 연결하고, 빌드 명령으로 Astro/Hugo/Next 등으로 markdown을 HTML로 만듭니다. - 주기 실행이 필요하면 GitHub Actions에서 이 스크립트를 cron으로 돌리면 됩니다. """ from __future__ import annotations import re import sys from datetime import date from pathlib import Path ROOT = Path(__file__).resolve().parents[1] POSTS_DIR = ROOT / "content" / "posts" def slugify(title: str) -> str: s = title.strip().lower() s = re.sub(r"\s+", "-", s) s = re.sub(r"[^a-z0-9가-힣\-]", "", s) s = re.sub(r"-{2,}", "-", s).strip("-") return s or "untitled" def build_frontmatter(title: str, d: date) -> str: return f"""--- title: "{title.replace('"', '\\"')}" date: {d.isoformat()} draft: true --- 여기에 본문을 작성하세요. """ def main() -> None: if len(sys.argv) > 1: title = " ".join(sys.argv[1:]).strip() else: title = input("글 제목: ").strip() if not title: print("제목이 비어 있습니다.", file=sys.stderr) sys.exit(1) POSTS_DIR.mkdir(parents=True, exist_ok=True) d = date.today() slug = slugify(title) path = POSTS_DIR / f"{d.isoformat()}-{slug}.md" if path.exists(): print(f"이미 있습니다: {path}", file=sys.stderr) sys.exit(1) path.write_text(build_frontmatter(title, d), encoding="utf-8") print(f"생성됨: {path}") if __name__ == "__main__": main()