Merge pull request #57 from ludovic111/website/contributors
Website: add a Contributors block to the community section
This commit is contained in:
+1
-1
@@ -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/*
|
||||
|
||||
@@ -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.
|
||||
|
||||
+8
-4
@@ -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
|
||||
|
||||
+21
-5
@@ -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(/</g, "\\u003c"),
|
||||
YEAR: String(new Date().getUTCFullYear()),
|
||||
};
|
||||
@@ -182,5 +198,5 @@ await writeFile(join(dist, ".csp-style"), hashes(/<style>([\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`,
|
||||
);
|
||||
|
||||
@@ -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 `<li><a class="contributor" href="${escape(c.html_url)}">${src ? `<img class="contributor-avatar" loading="lazy" decoding="async" src="${escape(src)}" width="48" height="48" alt="">` : `<span class="contributor-avatar" aria-hidden="true"></span>`}<span class="contributor-name">${escape(c.login)}</span><span class="contributor-count">${count}</span></a></li>`;
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
@@ -46,6 +46,7 @@
|
||||
<a href="#patch-notes">Notes</a>
|
||||
<a href="#next">Roadmap</a>
|
||||
<a href="#community">Community</a>
|
||||
<a href="#contributors" data-contributors{{CONTRIBUTORS_HIDDEN}}>Contributors</a>
|
||||
</nav>
|
||||
<div class="nav-end">
|
||||
<a class="nav-github" href="https://github.com/ludovic111/horizon">GitHub</a>
|
||||
@@ -64,6 +65,7 @@
|
||||
<a href="#patch-notes">Patch notes</a>
|
||||
<a href="#next">Roadmap</a>
|
||||
<a href="#community">Community</a>
|
||||
<a href="#contributors" data-contributors{{CONTRIBUTORS_HIDDEN}}>Contributors</a>
|
||||
</nav>
|
||||
<div class="menu-foot">
|
||||
<a class="button secondary large" href="https://github.com/ludovic111/horizon">GitHub</a>
|
||||
@@ -228,6 +230,11 @@
|
||||
<a class="card reveal" data-card data-link="sponsor" href="{{SPONSOR}}"><span class="card-title">Sponsor</span><span class="card-text">Sponsors on GitHub fund the next release.</span><span class="card-arrow" aria-hidden="true">→</span></a>
|
||||
<a class="card reveal" data-card href="https://github.com/ludovic111/horizon"><span class="card-title">Source</span><span class="card-text">Issues and pull requests are welcome.</span><span class="card-arrow" aria-hidden="true">→</span></a>
|
||||
</div>
|
||||
<div class="contributors" id="contributors" aria-labelledby="contributors-title" data-contributors{{CONTRIBUTORS_HIDDEN}}>
|
||||
<h3 class="contributors-title reveal" id="contributors-title">Contributors</h3>
|
||||
<p class="contributors-text reveal">Everyone who has committed to Horizon on GitHub, with how many commits.</p>
|
||||
<ul class="contributors-list reveal" id="contributors-list">{{CONTRIBUTORS}}</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
@@ -238,7 +245,7 @@
|
||||
<div class="footer-cols">
|
||||
<p>Horizon is made by <a href="https://lu4ovic.com">Ludovic Marie</a>, who is responsible for it and for this site; reach him through <a href="https://lu4ovic.com/#contact">lu4ovic.com</a>. Horizon contains no Minecraft code, assets or data, and this site offers no game files: you need your own legally obtained copy of Minecraft: Java Edition. Minecraft is a trademark of Mojang Synergies AB.</p>
|
||||
<p>Horizon's original work is under the <a href="https://github.com/ludovic111/horizon/blob/main/LICENSE">MIT licence</a>. The fonts are Geist and Instrument Serif, under the SIL Open Font License (<a href="/fonts/OFL-Geist.txt">Geist</a>, <a href="/fonts/OFL-InstrumentSerif.txt">Instrument Serif</a>). Every asset on this site is listed in <a href="/LEGAL.md">LEGAL.md</a>.</p>
|
||||
<p>Privacy: this site sets no cookies, has no analytics or trackers and loads nothing from third parties except GitHub. To show the latest releases, patch notes, roadmap and links, your browser asks <code>api.github.com</code> and <code>raw.githubusercontent.com</code> for them; <a href="https://docs.github.com/site-policy/privacy-policies/github-general-privacy-statement">GitHub's privacy statement</a> covers those requests.</p>
|
||||
<p>Privacy: this site sets no cookies, has no analytics or trackers and loads nothing from third parties except GitHub. To show the latest releases, patch notes, roadmap, links and contributors, your browser asks <code>api.github.com</code> and <code>raw.githubusercontent.com</code> for them, and <code>avatars.githubusercontent.com</code> for the contributors' pictures; <a href="https://docs.github.com/site-policy/privacy-policies/github-general-privacy-statement">GitHub's privacy statement</a> covers those requests.</p>
|
||||
</div>
|
||||
<div class="footer-bar">
|
||||
<span class="footer-mark">Horizon</span>
|
||||
|
||||
+14
-2
@@ -1,8 +1,9 @@
|
||||
// The page's behaviour: the download buttons for this platform, the latest releases, the
|
||||
// roadmap and links from main, the navigation, the menus' tabs, the lightbox and the motion.
|
||||
// roadmap, links and contributors, the navigation, the menus' tabs, the lightbox and the motion.
|
||||
// Everything degrades to the baked-in content when GitHub can't be reached.
|
||||
import { markdown, escape, section } from "./markdown.js";
|
||||
import { releasesHtml } from "./releases.js";
|
||||
import { contributorsFrom, contributorsHtml } from "./contributors.js";
|
||||
|
||||
const REPO = "ludovic111/horizon";
|
||||
const RELEASES_PAGE = `https://github.com/${REPO}/releases?q=launcher-v&expanded=true`;
|
||||
@@ -46,6 +47,16 @@ const releases = cached("horizon:releases", () =>
|
||||
),
|
||||
).catch(() => baked.releases);
|
||||
|
||||
async function setUpContributors() {
|
||||
let list = baked.contributors || [];
|
||||
try {
|
||||
list = contributorsFrom(await cached("horizon:contributors", () => get(`https://api.github.com/repos/${REPO}/contributors?per_page=100`)));
|
||||
} catch {}
|
||||
if (list.length) document.getElementById("contributors-list").innerHTML = contributorsHtml(list);
|
||||
// With nobody to show, the block and its menu entries go, as an empty link's card does.
|
||||
document.querySelectorAll("[data-contributors]").forEach((el) => (el.hidden = !list.length));
|
||||
}
|
||||
|
||||
// --- Download ------------------------------------------------------------------------
|
||||
|
||||
function platform() {
|
||||
@@ -119,7 +130,7 @@ function setUpNav() {
|
||||
const line = innerHeight * 0.4;
|
||||
let index = -1;
|
||||
sections.forEach((s, i) => {
|
||||
if (s.getBoundingClientRect().top <= line) index = i;
|
||||
if (s.getClientRects().length && s.getBoundingClientRect().top <= line) index = i;
|
||||
});
|
||||
if (index !== current) {
|
||||
current = index;
|
||||
@@ -316,3 +327,4 @@ setUpDownload();
|
||||
setUpNotes();
|
||||
setUpRoadmap();
|
||||
setUpLinks();
|
||||
setUpContributors();
|
||||
|
||||
@@ -58,6 +58,7 @@ p { margin: 0; }
|
||||
|
||||
a { color: var(--accent-text); text-decoration: none; transition: color var(--quick) var(--ease); }
|
||||
a:hover { color: var(--text); }
|
||||
[hidden] { display: none !important; }
|
||||
/* Links inside running text are underlined, so they don't rely on colour alone. */
|
||||
p a:not(.button):not(.link-arrow) { text-decoration: underline; text-decoration-color: rgba(164, 138, 230, 0.45); text-decoration-thickness: 1px; text-underline-offset: 3px; }
|
||||
p a:not(.button):not(.link-arrow):hover { text-decoration-color: currentColor; }
|
||||
@@ -561,6 +562,23 @@ code {
|
||||
.card:hover .card-arrow { transform: translateX(6px); color: var(--accent-text); }
|
||||
@media (min-width: 860px) { .cards { grid-template-columns: repeat(3, 1fr); } }
|
||||
|
||||
.contributors { margin-top: clamp(64px, 8vw, 112px); }
|
||||
.contributors-title { font: 400 clamp(28px, 3vw, 40px)/1.1 var(--display); letter-spacing: -0.015em; color: var(--text); }
|
||||
.contributors-text { margin-top: 10px; font-size: 15px; color: var(--muted); max-width: 46ch; }
|
||||
.contributors-list {
|
||||
display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); column-gap: 32px;
|
||||
list-style: none; margin-top: clamp(24px, 3vw, 36px); padding: 0;
|
||||
}
|
||||
.contributors-list li { border-top: 1px solid var(--border); }
|
||||
.contributor {
|
||||
display: grid; grid-template-columns: 48px 1fr; grid-template-rows: auto auto; column-gap: 16px; align-items: center;
|
||||
min-height: 44px; padding: 20px 0; color: var(--text);
|
||||
}
|
||||
.contributor-avatar { grid-row: 1 / 3; width: 48px; height: 48px; border-radius: 50%; background: var(--raised); border: 1px solid var(--border); object-fit: cover; }
|
||||
.contributor-name { align-self: end; font-size: 16px; font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; transition: color var(--quick) var(--ease); }
|
||||
.contributor-count { align-self: start; font: 12px/1.7 var(--mono); color: var(--faint); }
|
||||
.contributor:hover .contributor-name { color: var(--accent-text); }
|
||||
|
||||
/* --- Footer ------------------------------------------------------------------------- */
|
||||
|
||||
.footer { margin-top: clamp(112px, 14vw, 200px); border-top: 1px solid var(--border); padding-top: clamp(64px, 8vw, 104px); overflow: hidden; }
|
||||
|
||||
Reference in New Issue
Block a user