-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathupdate_how_it_works_image.py
executable file
·50 lines (38 loc) · 1.18 KB
/
update_how_it_works_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import subprocess
import sys
from pathlib import Path
try:
from html2image import Html2Image # type: ignore[import-not-found]
except ImportError:
sys.exit(
"""
html2image not found. Ensure you have Chrome (on Mac/Windows) or
Chromium (on Linux) installed, and then do:
pip install html2image
"""
)
def main() -> None:
subprocess.run(["mkdocs", "build"], check=True)
hti = Html2Image(custom_flags=["--force-device-scale-factor=2"])
html_str = Path("docs/diagram.md").read_text()
css_tags = f"""
<style>{Path("site/css/theme.css").read_text()}</style>
<style>{Path("site/css/theme_extra.css").read_text()}</style>
<style>{Path("site/extra.css").read_text()}</style>
<style>
body {{
background: white;
}}
</style>
"""
html_str = css_tags + html_str
[screenshot, *_] = hti.screenshot(
html_str=html_str,
size=(830, 405),
)
dest_path = Path("docs/data/how-it-works.png")
dest_path.unlink(missing_ok=True)
Path(screenshot).rename(dest_path)
if __name__ == "__main__":
main()