Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

site: fix stretched phone screenshots on the home page

Pixel (kwant bot)5b76b5003da1
diff --git a/scripts/check_site_images.py b/scripts/check_site_images.py
new file mode 100644
index 00000000..49a40d6b
--- /dev/null
+++ b/scripts/check_site_images.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env python3
+"""Checks that no <img> on the built site renders stretched or squashed.
+
+Serves site/ on a local port, loads every page in headless Chromium at desktop,
+tablet and phone widths, and compares each image's rendered aspect ratio with its
+real one. Images that crop on purpose (object-fit other than fill) are skipped.
+
+ python3 scripts/check_site_images.py # uses chromium / google-chrome on PATH
+ CHROME=/path/to/chrome python3 scripts/check_site_images.py
+
+Exits 1 and lists every distorted image if any are found.
+"""
+import functools
+import http.server
+import json
+import os
+import shutil
+import subprocess
+import sys
+import tempfile
+import threading
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parent.parent
+SITE = ROOT / "site"
+WIDTHS = [1440, 1280, 900, 390]
+TOLERANCE = 0.02 # 2 % difference between rendered and real aspect ratio
+
+HARNESS = """<!doctype html><meta charset="utf-8"><body><script>
+const pages = %(pages)s, widths = %(widths)s, results = [];
+async function measure(page, width) {
+ const f = document.createElement('iframe');
+ f.style.cssText = `width:${width}px;height:900px;border:0`;
+ document.body.append(f);
+ await new Promise(r => { f.onload = r; f.src = page; });
+ const d = f.contentDocument;
+ const imgs = [...d.querySelectorAll('img')];
+ imgs.forEach(i => { i.loading = 'eager'; });
+ await Promise.all(imgs.map(i => i.decode().catch(() => {})));
+ for (const i of imgs) {
+ const r = i.getBoundingClientRect(), fit = f.contentWindow.getComputedStyle(i).objectFit;
+ if (!r.width || !r.height || !i.naturalWidth || fit !== 'fill') continue;
+ const shown = r.height / r.width, real = i.naturalHeight / i.naturalWidth;
+ if (Math.abs(shown / real - 1) > %(tol)s)
+ results.push({page, width, src: i.getAttribute('src'), rendered: [Math.round(r.width), Math.round(r.height)],
+ natural: [i.naturalWidth, i.naturalHeight], stretch: +(shown / real).toFixed(2)});
+ }
+ f.remove();
+}
+(async () => {
+ let n = 0;
+ for (const p of pages) for (const w of widths) { await measure(p, w); n++; }
+ await fetch('/__result', {method: 'POST', body: JSON.stringify({checked: n, bad: results})});
+})();
+</script>"""
+
+
+def find_chrome():
+ for c in [os.environ.get("CHROME"), "chromium", "chromium-browser", "google-chrome", "google-chrome-stable"]:
+ if c and shutil.which(c):
+ return shutil.which(c)
+ sys.exit("check_site_images: no Chromium found; set CHROME=/path/to/chrome")
+
+
+def main():
+ pages = sorted(str(p.relative_to(SITE)) for p in SITE.rglob("*.html"))
+ harness = HARNESS % {"pages": json.dumps(pages), "widths": json.dumps(WIDTHS), "tol": TOLERANCE}
+
+ result, done = {}, threading.Event()
+
+ class Handler(http.server.SimpleHTTPRequestHandler):
+ def do_GET(self):
+ if self.path == "/__check_images.html":
+ body = harness.encode()
+ self.send_response(200)
+ self.send_header("Content-Type", "text/html; charset=utf-8")
+ self.send_header("Content-Length", str(len(body)))
+ self.end_headers()
+ self.wfile.write(body)
+ else:
+ super().do_GET()
+
+ def do_POST(self):
+ result.update(json.loads(self.rfile.read(int(self.headers["Content-Length"]))))
+ self.send_response(204)
+ self.end_headers()
+ done.set()
+
+ def log_message(self, *args):
+ pass
+
+ server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), functools.partial(Handler, directory=str(SITE)))
+ threading.Thread(target=server.serve_forever, daemon=True).start()
+ url = f"http://127.0.0.1:{server.server_address[1]}/__check_images.html"
+ with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as profile:
+ browser = subprocess.Popen(
+ [find_chrome(), "--headless", "--disable-gpu", "--no-sandbox", f"--user-data-dir={profile}", url],
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
+ )
+ finished = done.wait(300)
+ browser.terminate()
+ browser.wait()
+ server.shutdown()
+ if not finished:
+ sys.exit("check_site_images: the browser didn't finish measuring within 5 minutes")
+ data = result
+ for b in data["bad"]:
+ print(f"{b['page']} @ {b['width']}px: {b['src']} shows {b['rendered'][0]}x{b['rendered'][1]}, "
+ f"real ratio {b['natural'][0]}:{b['natural'][1]} (height stretched x{b['stretch']})")
+ print(f"check_site_images: {len(pages)} pages x {len(WIDTHS)} widths, {len(data['bad'])} distorted images")
+ return 1 if data["bad"] else 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/site/404.html b/site/404.html
index 8085598e..36acb82e 100644
--- a/site/404.html
+++ b/site/404.html
@@ -24,7 +24,7 @@
<link rel="apple-touch-icon" href="/apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="/assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="/assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="/assets/css/site.css?v=c6d8997040">
</head>
<body class="page-404">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/assets/css/site.css b/site/assets/css/site.css
index f83420f4..e6db3549 100644
--- a/site/assets/css/site.css
+++ b/site/assets/css/site.css
@@ -25,6 +25,7 @@
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 24px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 17px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
img, video, canvas { display: block; max-width: 100%; }
+img, video { height: auto; }
a { color: var(--v4); text-underline-offset: 3px; }
a:hover { color: var(--v5); }
code, pre, kbd { font-family: var(--mono); }
@@ -170,7 +171,8 @@ section { padding: 104px 0; }
.phone-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 56px; align-items: center; }
.phone-grid .row-copy > p:not(.kicker) { max-width: 30em; font-size: 18px; }
.phones { display: flex; gap: 22px; align-items: flex-start; }
-.phone { width: 230px; overflow: hidden; border: 8px solid var(--panel); border-radius: 30px; background: var(--panel); box-shadow: var(--shadow); }
+.phone { width: 250px; overflow: hidden; border: 8px solid var(--panel); border-radius: 30px; background: var(--panel); box-shadow: var(--shadow); }
+.phone img { width: 100%; }
.phone + .phone { margin-top: 40px; }
/* Setup steps: static, nothing to load */
diff --git a/site/docs/accounts.html b/site/docs/accounts.html
index 9dc359ee..7c37a184 100644
--- a/site/docs/accounts.html
+++ b/site/docs/accounts.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/approvals.html b/site/docs/approvals.html
index 3df8ce6c..4ea91f43 100644
--- a/site/docs/approvals.html
+++ b/site/docs/approvals.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/bots-and-teams.html b/site/docs/bots-and-teams.html
index 4c4388c9..7d0fcb9c 100644
--- a/site/docs/bots-and-teams.html
+++ b/site/docs/bots-and-teams.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/browser.html b/site/docs/browser.html
index 2fbe51be..0871e9a4 100644
--- a/site/docs/browser.html
+++ b/site/docs/browser.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/install.html b/site/docs/install.html
index 603b2ee4..25c2aa89 100644
--- a/site/docs/install.html
+++ b/site/docs/install.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/loose-ends.html b/site/docs/loose-ends.html
index 6b15e407..a9a51934 100644
--- a/site/docs/loose-ends.html
+++ b/site/docs/loose-ends.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/mcp.html b/site/docs/mcp.html
index df5af036..790e42ad 100644
--- a/site/docs/mcp.html
+++ b/site/docs/mcp.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/memory-skills.html b/site/docs/memory-skills.html
index ea5336ca..05119691 100644
--- a/site/docs/memory-skills.html
+++ b/site/docs/memory-skills.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/models.html b/site/docs/models.html
index 6c28e84b..24e55289 100644
--- a/site/docs/models.html
+++ b/site/docs/models.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/parallel-universe.html b/site/docs/parallel-universe.html
index 39a7c3a9..1fad4127 100644
--- a/site/docs/parallel-universe.html
+++ b/site/docs/parallel-universe.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/quickstart.html b/site/docs/quickstart.html
index 7d48213d..3ed82408 100644
--- a/site/docs/quickstart.html
+++ b/site/docs/quickstart.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/routines.html b/site/docs/routines.html
index d470203e..202f04cc 100644
--- a/site/docs/routines.html
+++ b/site/docs/routines.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/docs/spaces.html b/site/docs/spaces.html
index 7edd79e5..1a5c497c 100644
--- a/site/docs/spaces.html
+++ b/site/docs/spaces.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="../apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="../assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="../assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="../assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="../assets/css/site.css?v=c6d8997040">
</head>
<body class="page-docs">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/features.html b/site/features.html
index 54cd8e84..b2386d0d 100644
--- a/site/features.html
+++ b/site/features.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="assets/css/site.css?v=c6d8997040">
</head>
<body class="page-features">
<a class="skip" href="#main">Skip to content</a>
diff --git a/site/index.html b/site/index.html
index 9a7c4e41..4effb883 100644
--- a/site/index.html
+++ b/site/index.html
@@ -23,7 +23,7 @@
<link rel="apple-touch-icon" href="apple-touch-icon.png?v=1bc2442f39">
<link rel="preload" href="assets/fonts/pixelify-sans.woff2?v=66e897e155" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="assets/fonts/inter-var.woff2?v=3100e775e8" as="font" type="font/woff2" crossorigin>
-<link rel="stylesheet" href="assets/css/site.css?v=5a259a9358">
+<link rel="stylesheet" href="assets/css/site.css?v=c6d8997040">
</head>
<body class="page-home">
<a class="skip" href="#main">Skip to content</a>