Add automatic README screenshots (#730)

* add automatic README screenshots

* fix kerning
This commit is contained in:
mudkip authored and GitHub committed 2026-06-08 20:26:26 +00:00
1 parent df666a5703
commit 62f2fe80f7
10 files changed
+119 -4

No files matched your search

+14 -4
View File
@@ -1,13 +1,23 @@
<picture> <picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/user-attachments/assets/c6262803-c046-4e76-ac58-65458a93db07"> <source media="(prefers-color-scheme: dark)" srcset="screenshots/compact-dark.png">
<img alt="Photon light theme cozy" src="https://github.com/user-attachments/assets/bc72a843-013f-4b87-ae80-59a3b9132ecc" width="100%"> <img alt="Photon front page, compact layout" src="screenshots/compact-light.png" width="100%">
</picture>
<details>
<summary>Screenshots</summary>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="screenshots/cozy-dark.png">
<img alt="Photon front page, cozy layout" src="screenshots/cozy-light.png" width="100%">
</picture> </picture>
<picture> <picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/user-attachments/assets/c13f94c0-c2c4-48b2-b379-5ee714ae0556"> <source media="(prefers-color-scheme: dark)" srcset="screenshots/mobile-dark.png">
<img src="https://github.com/user-attachments/assets/11cf24c2-fd4f-480a-8a16-41f0f0a5b245"> <img alt="Photon communities page on mobile" src="screenshots/mobile-light.png" width="300">
</picture> </picture>
</details>
# Photon # Photon
Photon is a web app for the fediverse with helpful features and a nice UX. Photon is a web app for the fediverse with helpful features and a nice UX.
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
import pathlib
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError, sync_playwright
SITE = "https://phtn.app"
OUT_DIR = pathlib.Path(__file__).parent / "screenshots"
MOBILE_USER_AGENT = (
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) "
"AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1"
)
SCREENSHOTS = [
{"out": "compact-light.png", "path": "/", "width": 1280, "height": 800, "scheme": "light", "view": "compact", "wait": "article"},
{"out": "compact-dark.png", "path": "/", "width": 1280, "height": 800, "scheme": "dark", "view": "compact", "wait": "article"},
{"out": "cozy-light.png", "path": "/", "width": 1280, "height": 800, "scheme": "light", "view": "cozy", "wait": "article"},
{"out": "cozy-dark.png", "path": "/", "width": 1280, "height": 800, "scheme": "dark", "view": "cozy", "wait": "article"},
{"out": "mobile-light.png", "path": "/explore/communities", "width": 390, "height": 844, "scheme": "light", "mobile": True, "wait": "a[href^='/c/']"},
{"out": "mobile-dark.png", "path": "/explore/communities", "width": 390, "height": 844, "scheme": "dark", "mobile": True, "wait": "a[href^='/c/']"},
]
def capture(browser, shot):
mobile = shot.get("mobile", False)
context = browser.new_context(
viewport={"width": shot["width"], "height": shot["height"]},
device_scale_factor=2,
is_mobile=mobile,
has_touch=mobile,
user_agent=MOBILE_USER_AGENT if mobile else None,
)
# seed photon's color scheme and feed layout before the app boots
context.add_init_script(
f"localStorage.setItem('colorScheme', {shot['scheme']!r});"
f"localStorage.setItem('settings', JSON.stringify({{ view: {shot.get('view', 'compact')!r} }}));"
)
page = context.new_page()
page.goto(f"{SITE}{shot['path']}", wait_until="domcontentloaded")
try:
page.wait_for_selector(shot["wait"], timeout=30000)
page.wait_for_load_state("networkidle", timeout=15000)
page.evaluate("document.fonts.ready")
except PlaywrightTimeoutError:
pass
page.wait_for_timeout(1500)
page.screenshot(path=str(OUT_DIR / shot["out"]))
print(f"Wrote {shot['out']}")
context.close()
def main():
OUT_DIR.mkdir(parents=True, exist_ok=True)
with sync_playwright() as p:
# full chromium for correct kerning
browser = p.chromium.launch(channel="chromium")
try:
for shot in SCREENSHOTS:
capture(browser, shot)
finally:
browser.close()
if __name__ == "__main__":
main()
Binary file not shown.

After

Width:  |  Height:  |  Size: 458 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

+31
View File
@@ -0,0 +1,31 @@
name: Update README screenshots
on:
workflow_dispatch:
permissions:
contents: write
jobs:
screenshots:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.14"
- name: Install Playwright and Chromium
run: |
pip install playwright
python -m playwright install --with-deps chromium
- name: Capture screenshots
run: python .github/capture_screenshots.py
- name: Commit and push
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: Update README screenshots
file_pattern: .github/screenshots/*.png
+3
View File
@@ -17,3 +17,6 @@ playwright-report
test-results test-results
.vscode .vscode
*TS.md *TS.md
# Used for automated screenshot workflow
.github/__pycache__/