작업실: 새 작품 이미지도 함께 커밋, 되돌리기 뒤 빈 폴더 정리
This commit is contained in:
1 parent
767b2a30a3
commit
ca2c0d077d
2 files changed
+22
-3
No files matched your search
+17
-1
@@ -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}
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user