f53f198f03
website/ holds Horizon's site: the horizon-theme tokens and bundled fonts, the launcher's sidebar, rows, buttons and segmented control, over Horizon's own frozen landscape. The parity table, harness count and roadmap are generated from the README at build time; releases, patch notes, the roadmap and links.json are refreshed in the browser from GitHub, with the build's copy as fallback. The download button picks the newest launcher-v* asset for the visitor's OS. Legal: the Minecraft disclaimer in the hero, footer and 404; no Minecraft logo or wordmark; no game files; the launcher's background (licence unconfirmed) and the screenshots showing it are left out; LEGAL.md lists every asset and its licence. No cookies, analytics or third-party assets. Railway: root directory website, Dockerfile (Node build, Caddy on $PORT with a strict CSP). Checked with Playwright at 360-1920 px and 1250x700 (docs/widths/); Lighthouse 96/100/96/92 on mobile, 100/100/96/92 on desktop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
5.3 KiB
JavaScript
110 lines
5.3 KiB
JavaScript
// Full-page screenshots of the built site at every width that matters, plus the social
|
||
// preview image. Run `npm run build` first; `npm run shots` serves dist/ and writes
|
||
// docs/widths/*.png (and 390-menu.png, the open menu) and public/og.png (rebuild after).
|
||
// It also checks each width for horizontal scroll and small tap targets.
|
||
import { chromium } from "playwright";
|
||
import { spawn } from "node:child_process";
|
||
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
||
import sharp from "sharp";
|
||
import { join, dirname } from "node:path";
|
||
import { fileURLToPath } from "node:url";
|
||
|
||
const site = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||
const port = 4199;
|
||
const url = `http://localhost:${port}/`;
|
||
const server = spawn(process.execPath, [join(site, "serve.mjs")], { env: { ...process.env, PORT: String(port) }, stdio: "ignore" });
|
||
await new Promise((r) => setTimeout(r, 400));
|
||
|
||
const widths = [360, 390, 430, 768, 1024, 1180, 1250, 1280, 1366, 1440, 1680, 1920];
|
||
const sizes = [...widths.map((w) => [w, w < 900 ? 800 : 900]), [1250, 700]];
|
||
const only = process.argv.slice(2);
|
||
|
||
await mkdir(join(site, "docs/widths"), { recursive: true });
|
||
const browser = await chromium.launch();
|
||
let problems = 0;
|
||
|
||
for (const [width, height] of sizes) {
|
||
const name = height === 700 ? `${width}x${height}` : `${width}`;
|
||
if (only.length && !only.includes(name)) continue;
|
||
const touch = width < 900;
|
||
const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: 1, hasTouch: touch, isMobile: touch });
|
||
await page.goto(url, { waitUntil: "networkidle" });
|
||
// Reveal every section, as scrolling would, and let the fades finish.
|
||
await page.evaluate(async () => {
|
||
for (let y = 0; y < document.body.scrollHeight; y += 400) {
|
||
scrollTo({ top: y, behavior: "instant" });
|
||
await new Promise((r) => setTimeout(r, 30));
|
||
}
|
||
scrollTo({ top: 0, behavior: "instant" });
|
||
});
|
||
await page.waitForTimeout(800);
|
||
// A full-page capture draws fixed elements once, at the top; pin the sidebar to the whole
|
||
// page so the picture shows what a reader sees at every scroll position.
|
||
if (height !== 700 && !touch) {
|
||
await page.addStyleTag({ content: `.sidebar { position: absolute; bottom: auto; height: ${await page.evaluate(() => document.documentElement.scrollHeight)}px; }` });
|
||
}
|
||
const report = await page.evaluate((touch) => {
|
||
const out = [];
|
||
const doc = document.documentElement;
|
||
if (doc.scrollWidth > innerWidth) out.push(`horizontal scroll: ${doc.scrollWidth} > ${innerWidth}`);
|
||
for (const el of document.querySelectorAll("body *")) {
|
||
const r = el.getBoundingClientRect();
|
||
if (r.width && r.right > innerWidth + 1 && !el.closest(".table-scroll, .lightbox, .sidebar:not(.is-open)")) {
|
||
out.push(`overflows: ${el.tagName.toLowerCase()}.${el.className} right ${Math.round(r.right)}`);
|
||
}
|
||
}
|
||
if (touch) {
|
||
for (const el of document.querySelectorAll("a, button, summary")) {
|
||
if (el.closest(".sidebar:not(.is-open), .lightbox, .skip") || el.closest(".prose, .footer p:not(.footer-links), .row dd:not(.row-action), .table-meta, .parity")) continue;
|
||
const r = el.getBoundingClientRect();
|
||
if (r.width && r.height < 44) out.push(`small target: ${el.textContent.trim().slice(0, 30)} (${Math.round(r.height)}px)`);
|
||
}
|
||
}
|
||
// Characters per line of the longest running-text paragraphs.
|
||
const lengths = [...document.querySelectorAll(".prose p, .lede, .section-lede, .footer p")]
|
||
.filter((p) => p.textContent.length > 160)
|
||
.map((p) => {
|
||
const lh = parseFloat(getComputedStyle(p).lineHeight);
|
||
const n = Math.round(p.textContent.length / Math.max(1, Math.round(p.getBoundingClientRect().height / lh)));
|
||
return [n, `${p.parentElement.id || p.parentElement.className}>${p.className || p.tagName}`];
|
||
})
|
||
.sort((a, b) => a[0] - b[0]);
|
||
const [lo, hi] = [lengths[0], lengths[lengths.length - 1]];
|
||
out.push(`chars per line: ${lo[0]} (${lo[1]})–${hi[0]} (${hi[1]})`);
|
||
return out.slice(0, 12);
|
||
}, touch);
|
||
const issues = report.filter((l) => !l.startsWith("chars"));
|
||
problems += issues.length;
|
||
console.log(`${name}: ${issues.length ? issues.join("; ") : "ok"} · ${report.find((l) => l.startsWith("chars"))}`);
|
||
await page.screenshot({ path: join(site, `docs/widths/${name}.png`), fullPage: height !== 700 });
|
||
if (width === 390) {
|
||
await page.click(".menu-button");
|
||
await page.waitForTimeout(700);
|
||
await page.screenshot({ path: join(site, "docs/widths/390-menu.png") });
|
||
}
|
||
await page.close();
|
||
}
|
||
|
||
if (!only.length || only.includes("og")) {
|
||
const page = await browser.newPage({ viewport: { width: 1200, height: 630 } });
|
||
await page.goto(`${url}og.html`, { waitUntil: "networkidle" });
|
||
await page.waitForTimeout(700);
|
||
await page.screenshot({ path: join(site, "public/og.png") });
|
||
await page.close();
|
||
}
|
||
|
||
await browser.close();
|
||
server.kill();
|
||
|
||
// Keep the committed screenshots small: losslessly recompressed (a palette loses the 1px dividers).
|
||
for (const dir of ["docs/widths"]) {
|
||
for (const file of (await readdir(join(site, dir))).filter((f) => f.endsWith(".png"))) {
|
||
const path = join(site, dir, file);
|
||
await writeFile(path, await sharp(await readFile(path)).png({ compressionLevel: 9, adaptiveFiltering: true }).toBuffer());
|
||
}
|
||
}
|
||
if (problems) {
|
||
console.log(`${problems} problems`);
|
||
process.exitCode = 1;
|
||
}
|