From ca2c0d077d09ef124b958961636fd8812ed5cbde Mon Sep 17 00:00:00 2001 From: koreafood Date: Sat, 31 Oct 2026 11:19:50 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=91=EC=97=85=EC=8B=A4:=20=EC=83=88=20?= =?UTF-8?q?=EC=9E=91=ED=92=88=20=EC=9D=B4=EB=AF=B8=EC=A7=80=EB=8F=84=20?= =?UTF-8?q?=ED=95=A8=EA=BB=98=20=EC=BB=A4=EB=B0=8B,=20=EB=90=98=EB=8F=8C?= =?UTF-8?q?=EB=A6=AC=EA=B8=B0=20=EB=92=A4=20=EB=B9=88=20=ED=8F=B4=EB=8D=94?= =?UTF-8?q?=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- studio/server.py | 18 +++++++++++++++++- studio/smoke_test.py | 7 +++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/studio/server.py b/studio/server.py index 550b6b6..e8f53f5 100644 --- a/studio/server.py +++ b/studio/server.py @@ -188,6 +188,16 @@ def git_commit(message: str, paths: List[str]) -> Tuple[bool, str]: return ok, out.splitlines()[-1] if out else "" +def prune_empty_image_dirs() -> None: + """비어 있는 작품 이미지 폴더를 정리한다(되돌리기 뒤 찌꺼기 방지).""" + img_root = ASSETS / "img" + if not img_root.is_dir(): + return + for folder in sorted(img_root.iterdir()): + if folder.is_dir() and not any(folder.iterdir()): + folder.rmdir() + + def history(limit: int = 20) -> List[Dict[str, str]]: ok, out = git("log", f"-n{limit}", "--date=format:%Y-%m-%d %H:%M", "--pretty=format:%h\x1f%ad\x1f%s") if not ok: @@ -341,7 +351,12 @@ def save_product(payload: Dict[str, Any]) -> Dict[str, Any]: return {"ok": False, "stage": "build", "error": error, "log": build_log} label = "작품 추가" if creating else "작품 수정" - committed, commit_log = git_commit(f"{label}: {data.get('title') or slug}", [str(path.relative_to(ROOT))]) + # md 와 그 작품의 이미지 폴더를 함께 커밋한다(새 이미지가 untracked 로 남지 않도록) + paths = [str(path.relative_to(ROOT))] + image_dir = ASSETS / "img" / slug + if image_dir.is_dir(): + paths.append(str(image_dir.relative_to(ROOT))) + committed, commit_log = git_commit(f"{label}: {data.get('title') or slug}", paths) if not committed: return {"ok": False, "stage": "git", "error": "git 커밋 실패 (파일은 저장됨)", "log": commit_log} @@ -367,6 +382,7 @@ def revert(sha: str, redeploy: bool) -> Dict[str, Any]: if not ok: git("revert", "--abort") return {"ok": False, "error": "되돌리기 실패", "log": log} + prune_empty_image_dirs() built, build_log = build() if not built: return {"ok": False, "error": "되돌린 뒤 빌드 실패", "log": build_log} diff --git a/studio/smoke_test.py b/studio/smoke_test.py index 43f1807..71ffc3f 100644 --- a/studio/smoke_test.py +++ b/studio/smoke_test.py @@ -13,6 +13,9 @@ SLUG = "2026-10-whitework-tea-mat" MD = ROOT / "content/products" / f"{SLUG}.md" fails = [] +# 제목은 파일에서 읽는다(사용자가 스튜디오로 언제든 바꿀 수 있으므로 하드코딩하지 않는다) +TITLE = next(line.split(":", 1)[1].strip() for line in MD.read_text(encoding="utf-8").splitlines() + if line.startswith("title:")) def check(name, cond, extra=""): @@ -52,7 +55,7 @@ head0 = state["head"] # 2. 작품 열기 code, data = req(f"/api/product?slug={SLUG}") -check("GET /api/product", code == 200 and data["product"]["fields"]["title"] == "목련 한 땀 티매트", str(code)) +check("GET /api/product", code == 200 and data["product"]["fields"]["title"] == TITLE, str(code)) fields0 = data["product"]["fields"] body0 = data["product"]["body"] check("본문 읽힘", len(body0) > 50) @@ -79,7 +82,7 @@ check("목록 형식 유지(gallery)", "gallery:\n- assets/img/2026-10-whitework check("front matter 순서 유지", text.splitlines()[1].startswith("slug:"), text.splitlines()[1]) code, data = req("/api/history") -check("이력에 수정 커밋", any("목련 한 땀 티매트" in row["subject"] for row in data["history"]), str(data["history"][:2])) +check("이력에 수정 커밋", any(TITLE in row["subject"] for row in data["history"]), str(data["history"][:2])) # 5. 이미지 업로드 거부 (JPG 아님) code, data = req("/api/upload?name=x.png", raw=b"\x89PNG\r\n")