diff --git a/docs_assets/og/platforms/amberelec.png b/docs_assets/og/platforms/amberelec.png new file mode 100644 index 00000000..072bbf59 Binary files /dev/null and b/docs_assets/og/platforms/amberelec.png differ diff --git a/docs_assets/og/platforms/batocera.png b/docs_assets/og/platforms/batocera.png new file mode 100644 index 00000000..78a0712b Binary files /dev/null and b/docs_assets/og/platforms/batocera.png differ diff --git a/docs_assets/og/platforms/bizhawk.png b/docs_assets/og/platforms/bizhawk.png new file mode 100644 index 00000000..1a4e9a92 Binary files /dev/null and b/docs_assets/og/platforms/bizhawk.png differ diff --git a/docs_assets/og/platforms/emudeck.png b/docs_assets/og/platforms/emudeck.png new file mode 100644 index 00000000..0664e9aa Binary files /dev/null and b/docs_assets/og/platforms/emudeck.png differ diff --git a/docs_assets/og/platforms/emuelec.png b/docs_assets/og/platforms/emuelec.png new file mode 100644 index 00000000..0c11d700 Binary files /dev/null and b/docs_assets/og/platforms/emuelec.png differ diff --git a/docs_assets/og/platforms/knulli.png b/docs_assets/og/platforms/knulli.png new file mode 100644 index 00000000..45815db4 Binary files /dev/null and b/docs_assets/og/platforms/knulli.png differ diff --git a/docs_assets/og/platforms/lakka.png b/docs_assets/og/platforms/lakka.png new file mode 100644 index 00000000..5eb4050c Binary files /dev/null and b/docs_assets/og/platforms/lakka.png differ diff --git a/docs_assets/og/platforms/minui.png b/docs_assets/og/platforms/minui.png new file mode 100644 index 00000000..21cd1eae Binary files /dev/null and b/docs_assets/og/platforms/minui.png differ diff --git a/docs_assets/og/platforms/misterfpga.png b/docs_assets/og/platforms/misterfpga.png new file mode 100644 index 00000000..32cfc987 Binary files /dev/null and b/docs_assets/og/platforms/misterfpga.png differ diff --git a/docs_assets/og/platforms/myminui.png b/docs_assets/og/platforms/myminui.png new file mode 100644 index 00000000..bc3b0013 Binary files /dev/null and b/docs_assets/og/platforms/myminui.png differ diff --git a/docs_assets/og/platforms/nextui.png b/docs_assets/og/platforms/nextui.png new file mode 100644 index 00000000..a32a1e05 Binary files /dev/null and b/docs_assets/og/platforms/nextui.png differ diff --git a/docs_assets/og/platforms/recalbox.png b/docs_assets/og/platforms/recalbox.png new file mode 100644 index 00000000..43822f16 Binary files /dev/null and b/docs_assets/og/platforms/recalbox.png differ diff --git a/docs_assets/og/platforms/retroarch.png b/docs_assets/og/platforms/retroarch.png new file mode 100644 index 00000000..1d22e15c Binary files /dev/null and b/docs_assets/og/platforms/retroarch.png differ diff --git a/docs_assets/og/platforms/retrobat.png b/docs_assets/og/platforms/retrobat.png new file mode 100644 index 00000000..2bb5a8dc Binary files /dev/null and b/docs_assets/og/platforms/retrobat.png differ diff --git a/docs_assets/og/platforms/retrodeck.png b/docs_assets/og/platforms/retrodeck.png new file mode 100644 index 00000000..bdf6818b Binary files /dev/null and b/docs_assets/og/platforms/retrodeck.png differ diff --git a/docs_assets/og/platforms/retropie.png b/docs_assets/og/platforms/retropie.png new file mode 100644 index 00000000..901a3e88 Binary files /dev/null and b/docs_assets/og/platforms/retropie.png differ diff --git a/docs_assets/og/platforms/rocknix.png b/docs_assets/og/platforms/rocknix.png new file mode 100644 index 00000000..6a09bd19 Binary files /dev/null and b/docs_assets/og/platforms/rocknix.png differ diff --git a/docs_assets/og/platforms/romm.png b/docs_assets/og/platforms/romm.png new file mode 100644 index 00000000..786b0239 Binary files /dev/null and b/docs_assets/og/platforms/romm.png differ diff --git a/scripts/make_og_cards.py b/scripts/make_og_cards.py index e25f5731..c262c52c 100644 --- a/scripts/make_og_cards.py +++ b/scripts/make_og_cards.py @@ -5,40 +5,76 @@ Each card is an SVG written by ``sitediagrams.og_card_svg`` from the registry, rasterised by a headless Chromium through Playwright, then committed under ``docs_assets/og/``. The site build copies the PNG files and never runs this script, so it adds nothing to the build's dependencies. -Run it again when a section's wording or the platform count changes. +Run it again when a section's wording, the platform count or the list of +platforms changes. python scripts/make_og_cards.py + python scripts/make_og_cards.py --only platforms + +A platform page shares a card with its own name (``og/platforms/.png``), +the other pages their section's. """ from __future__ import annotations +import argparse import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT / "scripts")) +from common import list_registered_platforms, load_platform_config # noqa: E402 from sitediagrams import OG_SECTIONS, og_card_svg # noqa: E402 OUT = ROOT / "docs_assets" / "og" LOGO = ROOT / ".github" / "assets" / "logo.png" +PLATFORM_TAGLINE = "Which BIOS files it needs, and where each one goes" + + +def platform_cards() -> dict[str, str]: + """Each platform page's card, by its path under og/, with its title.""" + platforms = ROOT / "platforms" + return { + f"platforms/{name}": load_platform_config(name, str(platforms))["platform"] + for name in list_registered_platforms(str(platforms), include_archived=True) + } + + +def card_svg(key: str, logo: bytes, titles: dict[str, str]) -> str: + if key in OG_SECTIONS: + return og_card_svg(key, logo) + # A platform card is a section card with the platform's name for title. + OG_SECTIONS[key] = (titles[key], PLATFORM_TAGLINE) + try: + return og_card_svg(key, logo) + finally: + del OG_SECTIONS[key] def main() -> None: + parser = argparse.ArgumentParser(description="Render the sharing cards to PNG.", + allow_abbrev=False) + parser.add_argument("--only", choices=("sections", "platforms"), + help="render one kind of card (default: both)") + args = parser.parse_args() try: from playwright.sync_api import sync_playwright except ImportError as exc: raise SystemExit("Playwright with Chromium is needed: pip install playwright") from exc - OUT.mkdir(parents=True, exist_ok=True) + titles = platform_cards() + keys = [*([] if args.only == "platforms" else OG_SECTIONS), + *([] if args.only == "sections" else titles)] logo = LOGO.read_bytes() with sync_playwright() as playwright: browser = playwright.chromium.launch() page = browser.new_page(viewport={"width": 1200, "height": 630}) - for section in OG_SECTIONS: + for key in keys: page.set_content( - '' + og_card_svg(section, logo) + "" + '' + card_svg(key, logo, titles) + "" ) - path = OUT / f"{section}.png" + path = OUT / f"{key}.png" + path.parent.mkdir(parents=True, exist_ok=True) page.screenshot(path=str(path), clip={"x": 0, "y": 0, "width": 1200, "height": 630}) print(path.relative_to(ROOT)) browser.close()