Repository navigation
Expand file tree
/
Copy pathpreview.py
More file actions
34 lines (29 loc) · 1.63 KB
/
Copy pathpreview.py
File metadata and controls
34 lines (29 loc) · 1.63 KB
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
#!/usr/bin/env python3
"""Render every card in every theme from sample data into preview/index.html.
No token or network needed: python3 preview.py [samples/spidero.json]
Refresh the sample data: GITHUB_TOKEN=... python3 -m github_cards <login> /tmp/x --cards all --dump-data samples/<login>.json
"""
import os
import subprocess
import sys
from github_cards.__main__ import output_name
from github_cards.cards import load_cards
from github_cards.themes import THEMES
sample = sys.argv[1] if len(sys.argv) > 1 else "samples/spidero.json"
out = "preview"
subprocess.run([sys.executable, "-m", "github_cards", "--data", sample, "--cards", "all",
"--themes", ",".join(THEMES), "--activity-style", "both", "--star-repos", "x", "x", out], check=True, stdout=subprocess.DEVNULL)
rows = []
files = [(name + suffix, mod) for name, mod in load_cards().items()
for suffix, _ in getattr(mod, "variants", lambda o: [("", o)])({"activity_style": "both"})]
for name, mod in files:
imgs = "".join(
f'<div style="background:{"#8a8f98" if THEMES[t]["bg"] == "none" else THEMES[t]["bg"]};padding:16px">'
f'<div style="font:12px sans-serif;color:#999">{t}</div><img src="{output_name(name, t)}"></div>'
for t in THEMES
)
rows.append(f"<h2>{name}</h2><p>{mod.DESCRIPTION}</p><div style='display:flex;flex-wrap:wrap;gap:8px'>{imgs}</div>")
with open(os.path.join(out, "index.html"), "w", encoding="utf-8") as f:
f.write("<!doctype html><meta charset='utf-8'><title>Cards preview</title>"
"<body style='font-family:sans-serif;margin:24px'>" + "".join(rows))
print(f"open {os.path.abspath(out)}/index.html")