"""폴더 = 메뉴. wiki/08_화면 의 폴더 구조로 메뉴 HTML 과 화면목록.md 를 만든다. 폴더 이름 규칙: 숫자_메뉴이름 (숫자 = 순서). 폴더를 바꾸고 다시 실행하면 메뉴도 같이 바뀐다. 사용: python tools/build_menu.py → wiki/08_화면/menu.html, wiki/08_화면/00_화면목록.md""" import pathlib, re, html, urllib.parse ROOT = pathlib.Path(__file__).resolve().parent.parent SCR = ROOT / "wiki" / "08_화면" PAT = re.compile(r"^(\d+)_(.+)$") def menu_dirs(d): return sorted([p for p in d.iterdir() if p.is_dir() and PAT.match(p.name)], key=lambda p: int(PAT.match(p.name)[1])) def label(p): return PAT.match(p.name)[2] def status(p): f = p / "화면설명.md" if f.exists(): m = re.search(r"^status:\s*(\S+)", f.read_text(encoding="utf-8"), re.M) if m: return m[1] return "없음" def rel(p): return urllib.parse.quote(p.relative_to(SCR).as_posix()) def tree_html(d, depth=0): out = [] for p in menu_dirs(d): imgs = sorted(p.glob("화면*.png")) img = "|".join(rel(i) for i in imgs) # 슬라이드가 여러 장이면 전부 표시 proto = rel(p / "prototype.html") if (p / "prototype.html").exists() else "" # 실행 가능한 시제품 out.append(f'
  • ' f'{html.escape(label(p))} [{status(p)}]') sub = tree_html(p, depth + 1) if sub: out.append(f"") out.append("
  • ") return "".join(out) def tree_md(d, depth=0): lines = [] for p in menu_dirs(d): link = (p / "화면설명").relative_to(SCR.parent).as_posix() lines.append(f"{' ' * depth}- [[{link}|{label(p)}]] `{status(p)}`") lines += tree_md(p, depth + 1) return lines PAGE = """화면 메뉴 미리보기
    왼쪽 메뉴를 누르면 화면이 보입니다
    """ def main(): (SCR / "menu.html").write_text(PAGE.replace("__TREE__", tree_html(SCR)), encoding="utf-8") md = ["# 00_화면목록 (자동 생성 — 직접 수정하지 마세요)", "", "폴더를 추가/이름변경하고 `python tools/build_menu.py` 를 실행하면 갱신됩니다.", "브라우저 미리보기: `wiki/08_화면/menu.html`", ""] + tree_md(SCR) (SCR / "00_화면목록.md").write_text("\n".join(md) + "\n", encoding="utf-8") print("메뉴 갱신 완료:", SCR / "menu.html") if __name__ == "__main__": main()