BLOCK8 모델 단독 실행 HTML 생성
This commit is contained in:
1 parent
056a6448a2
commit
e3d9e7f955
3 files changed
+88
No files matched your search
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Vite 빌드 결과를 독립 실행 가능한 BLOCK8 HTML로 묶는다."""
|
||||
|
||||
from html.parser import HTMLParser
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
DIST = ROOT / "dist"
|
||||
OUTPUT = ROOT / "public/BLOCK8_모델웹페이지.html"
|
||||
|
||||
|
||||
class AssetParser(HTMLParser):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.script = None
|
||||
self.stylesheet = None
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
values = dict(attrs)
|
||||
if tag == "script" and values.get("src", "").startswith("/assets/"):
|
||||
self.script = values["src"].split("/assets/", 1)[1]
|
||||
if tag == "link" and values.get("rel") == "stylesheet" and values.get("href", "").startswith("/assets/"):
|
||||
self.stylesheet = values["href"].split("/assets/", 1)[1]
|
||||
|
||||
|
||||
def main():
|
||||
index = (DIST / "index.html").read_text(encoding="utf-8")
|
||||
parser = AssetParser()
|
||||
parser.feed(index)
|
||||
if not parser.script or not parser.stylesheet:
|
||||
raise RuntimeError("빌드된 HTML에서 JavaScript/CSS 파일을 찾지 못했습니다. npm run build를 먼저 실행하세요.")
|
||||
|
||||
js = (DIST / "assets" / parser.script).read_text(encoding="utf-8")
|
||||
css = (DIST / "assets" / parser.stylesheet).read_text(encoding="utf-8")
|
||||
# public 폴더 안의 자료 링크가 file:// 환경에서도 열리도록 상대 경로로 바꾼다.
|
||||
for path in ("analysis/", "drawings/", "BLOCK8_", "작업기록.txt"):
|
||||
js = js.replace(f"/{path}", f"./{path}")
|
||||
|
||||
title = re.search(r"<title>(.*?)</title>", index, re.DOTALL)
|
||||
page_title = title.group(1) if title else "광터지하차도 BLOCK8 3D 모델"
|
||||
html = f'''<!doctype html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="theme-color" content="#eff2ed">
|
||||
<meta name="description" content="도면의 중심선과 구조 단면을 연결한 광터지하차도 BLOCK8 3D 검토 모델입니다.">
|
||||
<title>{page_title}</title>
|
||||
<style>{css}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module">{js}</script>
|
||||
</body>
|
||||
</html>
|
||||
'''
|
||||
OUTPUT.write_text(html, encoding="utf-8")
|
||||
print(f"{OUTPUT.relative_to(ROOT)} 생성 완료 ({OUTPUT.stat().st_size:,} bytes)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user