diff --git a/website/Caddyfile b/website/Caddyfile index ebda45386..f0ba13136 100644 --- a/website/Caddyfile +++ b/website/Caddyfile @@ -20,7 +20,7 @@ Referrer-Policy strict-origin-when-cross-origin X-Frame-Options DENY Permissions-Policy "interest-cohort=(), browsing-topics=(), camera=(), microphone=(), geolocation=()" - Content-Security-Policy "default-src 'self'; script-src 'self' {$CSP_SCRIPT}; style-src 'self' {$CSP_STYLE}; img-src 'self' data:; font-src 'self'; connect-src 'self' https://api.github.com https://raw.githubusercontent.com; frame-ancestors 'none'; base-uri 'self'; form-action 'self'" + Content-Security-Policy "default-src 'self'; script-src 'self' {$CSP_SCRIPT}; style-src 'self' {$CSP_STYLE}; img-src 'self' data: https://avatars.githubusercontent.com; font-src 'self'; connect-src 'self' https://api.github.com https://raw.githubusercontent.com; frame-ancestors 'none'; base-uri 'self'; form-action 'self'" -Server } @assets path /assets/* diff --git a/website/LEGAL.md b/website/LEGAL.md index 28c3dc606..ba709abed 100644 --- a/website/LEGAL.md +++ b/website/LEGAL.md @@ -74,3 +74,10 @@ files: players need their own legally obtained copy of Minecraft: Java Edition. The parity table and the roadmap are generated from Horizon's README, and the patch notes come from Horizon's GitHub releases: Horizon's own text, MIT. + +## Contributors + +The Contributors block lists the GitHub accounts that have committed to Horizon: login, +commit count and profile link, from GitHub's API. Their avatars are not stored in this repository; +the visitor's browser loads them from `avatars.githubusercontent.com`, each one the picture its +owner chose for their GitHub account. Bots are left out. diff --git a/website/README.md b/website/README.md index 7a2e6d319..36fdcb5c8 100644 --- a/website/README.md +++ b/website/README.md @@ -6,7 +6,7 @@ One static page in the launcher's design language rather than its layout: the pa violet accent of `crates/horizon-theme`, Instrument Serif for display type and Geist for the rest, 1px dividers and short, eased motion. A full-viewport hero over Horizon's own sunset, then a scroll through what it is, the screenshots, the parity grid, the launcher, the patch -notes, the roadmap and the community links. Plain HTML, CSS and JavaScript; no framework and +notes, the roadmap, the community links and the contributors. Plain HTML, CSS and JavaScript; no framework and no runtime dependencies. ## Layout @@ -17,9 +17,10 @@ serve.mjs a tiny static server for local checks src/index.html the page, with {{placeholders}} build.mjs fills src/404.html the not-found page src/style.css the design tokens and every style -src/main.js download buttons, patch notes, roadmap, links, nav and menu, tabs, lightbox, motion +src/main.js download buttons, patch notes, roadmap, links, contributors, nav and menu, tabs, lightbox, motion src/markdown.js a small Markdown renderer (escapes everything), shared by build and page src/releases.js the patch notes' markup, shared by build and page +src/contributors.js the contributors' filtering and markup, shared by build and page public/ fonts, screenshots, the hero, icons, og.png, robots.txt, sitemap.xml: copied as is scripts/assets.mjs rebuilds public/ from the repo (fonts to WOFF2, images to WebP) scripts/shots.mjs Playwright screenshots at every width, and og.png @@ -32,12 +33,15 @@ shots/ (gitignored) full-page screenshots at 360–1920 px, a 1250× - **Built in** (`build.mjs`): the parity table, its score, harness count and audit date, and the roadmap, all from `README.md`; the Discord and Sponsor links from - `launcher/links.json`; the latest releases, when GitHub answers. Locally these come from + `launcher/links.json`; the latest releases and the contributors (`/repos/ludovic111/horizon/contributors`, + bots left out, the owner first), when GitHub answers; without an answer the build still succeeds and + the Contributors block and its menu entries stay hidden until the page loads them. Locally these come from the checkout; on Railway, which builds only this folder, from `main` on GitHub. The build fails if the README has no parity table or roadmap, so a broken README never deploys. - **Fetched by the page**: the releases (the download button picks the newest `launcher-v*` release's asset for the visitor's OS, and the three latest game releases' - notes are rendered), the roadmap from the raw README on `main`, and `links.json`. Each + notes are rendered), the contributors (avatars come from `avatars.githubusercontent.com`), + the roadmap from the raw README on `main`, and `links.json`. Each falls back to what was built in, and the download button to the releases page. ## Run it locally diff --git a/website/build.mjs b/website/build.mjs index 0edf6d53c..4c725dbb7 100644 --- a/website/build.mjs +++ b/website/build.mjs @@ -1,9 +1,9 @@ // Builds the site into dist/: src/index.html with the README's parity table, roadmap and -// the community links baked in, plus public/ and fingerprinted CSS and JS. No dependencies. +// the community links and contributors baked in, plus public/ and fingerprinted CSS and JS. No dependencies. // // Railway builds only website/, so the README and links.json come from the repo when they -// are next to it (a local checkout) and from main on GitHub otherwise. The latest releases -// are baked in when GitHub answers, so the page reads well before (or without) JavaScript. +// are next to it (a local checkout) and from main on GitHub otherwise. The latest releases and +// the contributors are baked in when GitHub answers, so the page reads well before (or without) JavaScript. import { readFile, writeFile, mkdir, rm, cp } from "node:fs/promises"; import { existsSync } from "node:fs"; import { createHash } from "node:crypto"; @@ -11,6 +11,7 @@ import { join, dirname } from "node:path"; import { fileURLToPath } from "node:url"; import { markdown, inline, section, escape } from "./src/markdown.js"; import { releasesHtml } from "./src/releases.js"; +import { contributorsFrom, contributorsHtml } from "./src/contributors.js"; const site = dirname(fileURLToPath(import.meta.url)); const dist = join(site, "dist"); @@ -50,6 +51,18 @@ try { console.warn(`releases: ${e.message}; the page will load them itself`); } +let contributors = []; +try { + const res = await fetch(`https://api.github.com/repos/${REPO}/contributors?per_page=100`, { + headers: { Accept: "application/vnd.github+json", ...(process.env.GITHUB_TOKEN ? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } : {}) }, + signal: AbortSignal.timeout(15000), + }); + if (res.ok) contributors = contributorsFrom(await res.json()); + else console.warn(`contributors: ${res.status} from GitHub; the page will load them itself`); +} catch (e) { + console.warn(`contributors: ${e.message}; the page will load them itself`); +} + // --- The parity table ------------------------------------------------------------------ const status = section(readme, "Project status") ?? ""; @@ -115,7 +128,7 @@ await cp(join(site, "LEGAL.md"), join(dist, "LEGAL.md")); // The page's modules, fingerprinted; each import of a shared module is rewritten to its name. const names = {}; const rewrite = (code) => code.replace(/"\.\/(\w+\.js)"/g, (all, file) => (names[file] ? `"./${names[file]}"` : all)); -for (const file of ["markdown.js", "releases.js", "main.js"]) { +for (const file of ["markdown.js", "releases.js", "contributors.js", "main.js"]) { const code = rewrite(await readFile(join(site, "src", file), "utf8")); names[file] = `${file.replace(".js", "")}.${fingerprint(code)}.js`; await writeFile(join(dist, "assets", names[file]), code); @@ -129,6 +142,7 @@ const inlineCss = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\s*\n\s*/g, "\n" const baked = { links, + contributors, releases: releases.slice(0, 12).map((r) => ({ tag_name: r.tag_name, name: r.name, @@ -160,6 +174,8 @@ const values = { LAUNCHER_META: `${launcher ? `Launcher ${escape(launcher.tag_name.replace("launcher-v", ""))} for` : "For"} Linux x86-64, macOS on Apple Silicon and Windows x64.`, DISCORD: escape(links.discord || DEFAULT_LINKS.discord), SPONSOR: escape(links.sponsor || DEFAULT_LINKS.sponsor), + CONTRIBUTORS: contributorsHtml(contributors), + CONTRIBUTORS_HIDDEN: contributors.length ? "" : " hidden", BAKED: JSON.stringify(baked).replace(/([\s\S]*?)<\/style>/g)) console.log( `built dist/ from ${readmeFrom}: ${body.length} subsystems, ${percent}, ${harnesses} harnesses, ` + - `${game.length} game releases baked${launcher ? `, launcher ${launcher.tag_name}` : ""}`, + `${game.length} game releases baked${launcher ? `, launcher ${launcher.tag_name}` : ""}, ${contributors.length} contributors`, ); diff --git a/website/src/contributors.js b/website/src/contributors.js new file mode 100644 index 000000000..5d2030f5e --- /dev/null +++ b/website/src/contributors.js @@ -0,0 +1,39 @@ +// The contributors: GitHub's list for the repository, without bots, the owner first. Shared by +// build.mjs (baked into the page) and main.js (refreshed from GitHub). +import { escape } from "./markdown.js"; + +const OWNER = "ludovic111"; +const AVATARS = "https://avatars.githubusercontent.com/"; + +// Reduces GitHub's contributor objects to what the page shows; bots (type Bot, or a login +// ending in [bot]) and anything without a login or a profile address are dropped. +export function contributorsFrom(list) { + if (!Array.isArray(list)) return []; + return list + .filter((c) => c && typeof c.login === "string" && c.login && c.type !== "Bot" && !/\[bot\]$/i.test(c.login)) + .map((c) => ({ + login: c.login, + html_url: typeof c.html_url === "string" ? c.html_url : `https://github.com/${c.login}`, + avatar_url: typeof c.avatar_url === "string" ? c.avatar_url : "", + contributions: Number(c.contributions) || 0, + })) + .sort((a, b) => (b.login === OWNER) - (a.login === OWNER) || b.contributions - a.contributions); +} + +// GitHub serves avatars at any size: 96 px is twice what the page draws, for sharp screens. +function avatar(url) { + if (!url.startsWith(AVATARS)) return ""; + const u = new URL(url); + u.searchParams.set("s", "96"); + return u.href; +} + +export function contributorsHtml(list) { + return list + .map((c) => { + const src = avatar(c.avatar_url); + const count = `${c.contributions.toLocaleString("en-US")} ${c.contributions === 1 ? "commit" : "commits"}`; + return `