65 lines
2.7 KiB
Python
65 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""deck.src.html → index.html (самодостаточная: шрифты и логотип инлайн) + PDF.
|
|
|
|
python3 decks/shkor-labs-fundraise/build.py [--pdf] [--png]
|
|
"""
|
|
import base64
|
|
import glob
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
ROOT = os.path.dirname(os.path.dirname(HERE))
|
|
ASSETS = os.path.join(ROOT, "sites", "shkor-com", "v2", "assets")
|
|
|
|
|
|
def b64(name):
|
|
with open(os.path.join(ASSETS, name), "rb") as f:
|
|
return "data:font/woff2;base64," + base64.b64encode(f.read()).decode()
|
|
|
|
|
|
LOGO = ('<svg width="30" height="30" viewBox="0 0 200 200"><circle cx="100" cy="100" r="78" '
|
|
'fill="none" stroke="#c6ff4d" stroke-width="12" stroke-dasharray="20 27" '
|
|
'stroke-linecap="round"/><circle cx="100" cy="100" r="30" fill="#c6ff4d"/></svg>')
|
|
|
|
|
|
def build():
|
|
src = open(os.path.join(HERE, "deck.src.html"), encoding="utf-8").read()
|
|
for k, v in {"__FONT_INTER400__": "inter-400-latin.woff2",
|
|
"__FONT_INTER600__": "inter-600-latin.woff2",
|
|
"__FONT_SPACE__": "space-grotesk-latin.woff2",
|
|
"__FONT_MONO__": "jetbrains-mono-400-latin.woff2"}.items():
|
|
src = src.replace(k, b64(v))
|
|
src = src.replace("__LOGO_SMALL__", LOGO)
|
|
out = os.path.join(HERE, "index.html")
|
|
open(out, "w", encoding="utf-8").write(src)
|
|
return out
|
|
|
|
|
|
def chrome():
|
|
c = glob.glob(os.path.expanduser("~/.cache/ms-playwright/chromium_headless_shell-*/*/chrome-headless-shell"))
|
|
return c[0] if c else None
|
|
|
|
|
|
if __name__ == "__main__":
|
|
out = build()
|
|
print("OK", os.path.relpath(out, ROOT), os.path.getsize(out) // 1024, "KB", file=sys.stderr)
|
|
ch = chrome()
|
|
if "--pdf" in sys.argv and ch:
|
|
pdf = os.path.join(HERE, "Shkor_Labs_Pre-seed_2026-10.pdf")
|
|
subprocess.run([ch, "--no-sandbox", "--disable-gpu", "--run-all-compositor-stages-before-draw",
|
|
"--virtual-time-budget=3000", "--no-pdf-header-footer",
|
|
f"--print-to-pdf={pdf}", "file://" + out], check=True, capture_output=True)
|
|
print("OK", os.path.relpath(pdf, ROOT), file=sys.stderr)
|
|
if "--png" in sys.argv and ch:
|
|
d = os.path.join("/tmp", "deck-png")
|
|
os.makedirs(d, exist_ok=True)
|
|
n = len(re.findall(r'<section class="slide', open(out).read()))
|
|
for i in range(1, n + 1):
|
|
subprocess.run([ch, "--no-sandbox", "--disable-gpu", "--hide-scrollbars",
|
|
"--window-size=1920,1080", "--virtual-time-budget=2500",
|
|
f"--screenshot={d}/s{i:02d}.png", f"file://{out}#{i}"],
|
|
check=True, capture_output=True)
|
|
print("OK png →", d, file=sys.stderr)
|