Merge feat/roadmap-hub (main's registry pages) into feat/hub-board
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
// /mods and /mods/<id>: the registry's list (kind filter, search) and a project's page. The pages are baked from
|
||||
// the index at build time; this fetches the published index again so a project merged since shows at once.
|
||||
import { INDEX_URL, KINDS, listHtml, matches, projectHtml, readIndex } from "./mods.js";
|
||||
import { cached, setUpMenu, setUpTheme } from "./chrome.js";
|
||||
|
||||
const root = document.getElementById("mods");
|
||||
const baked = readIndex(JSON.parse(document.getElementById("mods-index").textContent || "null")) || [];
|
||||
let projects = baked;
|
||||
let kind = "all";
|
||||
let text = "";
|
||||
|
||||
const id = (location.pathname.match(/^\/mods\/([a-z0-9_]+)\/?$/) || [])[1];
|
||||
|
||||
function showList() {
|
||||
const list = root.querySelector("#mod-list");
|
||||
if (!list) return;
|
||||
const shown = projects.filter((p) => matches(p, kind, text));
|
||||
list.innerHTML = listHtml(shown);
|
||||
root.querySelector("[data-mod-count]").textContent = `${shown.length} of ${projects.length}`;
|
||||
root.querySelectorAll("[data-kind-filter]").forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.kindFilter === kind)));
|
||||
}
|
||||
|
||||
function showProject() {
|
||||
const p = projects.find((x) => x.id === id);
|
||||
const page = root.querySelector(".mod-page, .mod-missing");
|
||||
if (!page) return;
|
||||
if (p) {
|
||||
page.outerHTML = projectHtml(p);
|
||||
document.title = `${p.name} · Horizon`;
|
||||
} else {
|
||||
page.outerHTML = `<div class="mod-missing"><h1 class="display page-title">Not in the registry</h1><p class="lede">No project is called ${id} here. It may not be published yet, or it was taken down.</p><a class="button secondary" href="/mods">Every mod</a></div>`;
|
||||
}
|
||||
}
|
||||
|
||||
function render() {
|
||||
if (id) showProject();
|
||||
else showList();
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
root.querySelectorAll("[data-kind-filter]").forEach((b) =>
|
||||
b.addEventListener("click", () => {
|
||||
kind = b.dataset.kindFilter;
|
||||
showList();
|
||||
}),
|
||||
);
|
||||
root.querySelector("#mod-search")?.addEventListener("input", (e) => {
|
||||
text = e.target.value;
|
||||
showList();
|
||||
});
|
||||
const wanted = new URLSearchParams(location.search).get("kind");
|
||||
if (KINDS.some(([k]) => k === wanted)) kind = wanted;
|
||||
}
|
||||
|
||||
setUpTheme();
|
||||
setUpMenu();
|
||||
render();
|
||||
cached("horizon:mod-index", () => fetch(INDEX_URL).then((r) => (r.ok ? r.json() : Promise.reject(new Error(`${r.status}`)))))
|
||||
.then((index) => {
|
||||
const fresh = readIndex(index);
|
||||
if (fresh) {
|
||||
projects = fresh;
|
||||
render();
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
@@ -0,0 +1,80 @@
|
||||
// /mods/submit: signs in with GitHub through the registry's service, then sends the page and the file. The service
|
||||
// checks the file and answers with the pull request it opened, or with what to fix.
|
||||
import { API, entryFrom } from "./mods.js";
|
||||
import { setUpMenu, setUpTheme } from "./chrome.js";
|
||||
import { escape } from "./markdown.js";
|
||||
|
||||
const auth = document.getElementById("submit-auth");
|
||||
const form = document.getElementById("submit-form");
|
||||
const result = document.getElementById("submit-result");
|
||||
let csrf = "";
|
||||
// The form's own controls by name (form.id and form.name are the form's attributes).
|
||||
const control = (name) => form.elements.namedItem(name);
|
||||
|
||||
function signedOut(message) {
|
||||
auth.innerHTML = `<p class="meta">${message}</p><p class="mod-actions"><a class="button primary" href="${API}/auth/login">Sign in with GitHub</a></p><p class="meta">It only reads your public profile: your GitHub name goes on the pull request and in the project's owners.</p>`;
|
||||
form.hidden = true;
|
||||
}
|
||||
|
||||
async function start() {
|
||||
let me;
|
||||
try {
|
||||
const r = await fetch(`${API}/me`, { credentials: "same-origin" });
|
||||
if (r.status === 401) return signedOut("Sign in to submit: reviewers and updates go through your GitHub account.");
|
||||
if (!r.ok) throw new Error(String(r.status));
|
||||
me = await r.json();
|
||||
} catch {
|
||||
auth.innerHTML = `<p class="meta">The form isn't open right now. You can <a href="https://github.com/ludovic111/horizon-mods">open a pull request by hand</a>.</p>`;
|
||||
return;
|
||||
}
|
||||
csrf = me.csrf;
|
||||
auth.innerHTML = `<p class="meta">Signed in as <strong>${escape(me.login)}</strong>. <button class="button ghost small" type="button" id="sign-out">Sign out</button></p>`;
|
||||
document.getElementById("sign-out").addEventListener("click", async () => {
|
||||
await fetch(`${API}/auth/logout`, { method: "POST", credentials: "same-origin" });
|
||||
signedOut("Signed out.");
|
||||
});
|
||||
form.hidden = false;
|
||||
}
|
||||
|
||||
// A file named <id>-<version>.<extension> fills in the two fields and the kind.
|
||||
form.querySelector("#f-file").addEventListener("change", (e) => {
|
||||
const name = e.target.files[0]?.name || "";
|
||||
const m = name.match(/^([a-z0-9_]{1,64})-([A-Za-z0-9][A-Za-z0-9._-]*)\.(hmod|hpack|zip)$/);
|
||||
const kind = { hmod: "mod", hpack: "modpack", zip: "resourcepack" }[name.split(".").pop()];
|
||||
if (kind) control("kind").value = kind;
|
||||
if (m) {
|
||||
if (!control("id").value) control("id").value = m[1];
|
||||
if (!control("version").value) control("version").value = m[2];
|
||||
}
|
||||
});
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const send = form.querySelector("#f-send");
|
||||
const values = Object.fromEntries(["id", "kind", "name", "summary", "description", "authors", "license", "source", "icon", "key", "version", "game", "changelog"].map((k) => [k, control(k).value]));
|
||||
const sig = form.querySelector("#f-signature").files[0];
|
||||
values.signature = sig ? await sig.text() : "";
|
||||
const body = new FormData();
|
||||
body.append("entry", JSON.stringify(entryFrom(values)));
|
||||
body.append("file", form.querySelector("#f-file").files[0]);
|
||||
send.disabled = true;
|
||||
result.innerHTML = `<p class="meta">Checking the file and opening the pull request…</p>`;
|
||||
try {
|
||||
const r = await fetch(`${API}/submit`, { method: "POST", body, credentials: "same-origin", headers: { "X-CSRF-Token": csrf } });
|
||||
const json = await r.json().catch(() => ({}));
|
||||
if (r.ok && /^https:\/\/github\.com\//.test(json.pull_request || "")) {
|
||||
result.innerHTML = `<p class="lede">Submitted. Follow the review in <a href="${escape(json.pull_request)}">its pull request</a>: the checks' report is there, and reviewers answer there.</p>`;
|
||||
form.reset();
|
||||
} else {
|
||||
result.innerHTML = `<p class="mod-error">${escape(json.error || `The service answered ${r.status}.`)}</p>`;
|
||||
}
|
||||
} catch {
|
||||
result.innerHTML = `<p class="mod-error">The service didn't answer. Try again in a minute.</p>`;
|
||||
} finally {
|
||||
send.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
setUpTheme();
|
||||
setUpMenu();
|
||||
start();
|
||||
@@ -0,0 +1,37 @@
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<title>{{MODS_TITLE}} · Horizon</title>
|
||||
<meta name="description" content="{{MODS_DESCRIPTION}}">
|
||||
<meta name="theme-color" content="#ece7f7" media="(prefers-color-scheme: light)">
|
||||
<meta name="theme-color" content="#0f0d17" media="(prefers-color-scheme: dark)">
|
||||
<meta name="color-scheme" content="light dark">
|
||||
<link rel="canonical" href="https://playhorizon.dev{{MODS_PATH}}">
|
||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
||||
<link rel="icon" href="/favicon-32.png" sizes="32x32" type="image/png">
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:site_name" content="Horizon">
|
||||
<meta property="og:title" content="{{MODS_TITLE}} · Horizon">
|
||||
<meta property="og:description" content="{{MODS_DESCRIPTION}}">
|
||||
<meta property="og:url" content="https://playhorizon.dev{{MODS_PATH}}">
|
||||
<meta property="og:image" content="https://playhorizon.dev/og.png">
|
||||
<style>{{STYLE}}</style>
|
||||
<script>document.documentElement.classList.replace("no-js", "js"); try { const t = localStorage.getItem("theme"); if (t === "light" || t === "dark") document.documentElement.dataset.theme = t } catch {}</script>
|
||||
<script type="module" src="{{MODS_JS}}"></script>
|
||||
</head>
|
||||
<body class="subpage">
|
||||
<a class="skip" href="#main">Skip to the content</a>
|
||||
{{SITE_NAV}}
|
||||
<main id="main" class="section page-main">
|
||||
<div class="container" id="mods" data-baked="{{MODS_BAKED_AT}}">
|
||||
{{MODS_MAIN}}
|
||||
<p class="disclaimer">Not an official Minecraft product. Not approved by or associated with Mojang or Microsoft.</p>
|
||||
</div>
|
||||
</main>
|
||||
{{SITE_FOOTER}}
|
||||
<script type="application/json" id="mods-index">{{MODS_DATA}}</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,188 @@
|
||||
// Horizon's registry on the site (/mods): the list with its kind filter and search, and a page per project.
|
||||
// Shared by build.mjs (baked into the pages) and mods-page.js (refreshed from the published index).
|
||||
// The index's format is docs/api/mod-index.md in the repository.
|
||||
import { markdown, escape } from "./markdown.js";
|
||||
|
||||
export const INDEX_URL = "https://ludovic111.github.io/horizon-mods/index.json";
|
||||
const REGISTRY = "https://github.com/ludovic111/horizon-mods";
|
||||
export const SUBMIT = "/mods/submit";
|
||||
// The submission form's service (crates/horizon-mod-registry), behind the site's own address.
|
||||
export const API = "/api/mods";
|
||||
export const SCHEMA = 1;
|
||||
|
||||
// The kinds the site shows, in the filter's order. Kinds a newer index adds are left out until the site knows them.
|
||||
export const KINDS = [
|
||||
["mod", "Mods"],
|
||||
["modpack", "Modpacks"],
|
||||
["resourcepack", "Resource packs"],
|
||||
["shader", "Shader packs"],
|
||||
];
|
||||
const KIND_NAMES = { mod: "Mod", modpack: "Modpack", resourcepack: "Resource pack", shader: "Shader pack" };
|
||||
|
||||
// What a capability lets a mod do, as the game and the launcher say it (horizon_mods::Capability::describe).
|
||||
export const CAPABILITIES = {
|
||||
"game-read": "see your position, health and the time",
|
||||
chat: "show you chat messages",
|
||||
hud: "draw text on your screen",
|
||||
storage: "save its own settings to disk",
|
||||
registries: "add blocks and items to your worlds",
|
||||
};
|
||||
|
||||
// The index's projects this site can show, or null when it isn't an index it reads.
|
||||
export function readIndex(index) {
|
||||
if (!index || typeof index !== "object" || index.schema > SCHEMA || !Array.isArray(index.projects)) return null;
|
||||
const known = new Set(KINDS.map(([k]) => k));
|
||||
return index.projects.filter((p) => known.has(p.kind) && /^[a-z0-9_]{1,64}$/.test(p.id) && p.versions?.length);
|
||||
}
|
||||
|
||||
const https = (url) => (typeof url === "string" && url.startsWith("https://") ? url : "");
|
||||
const size = (bytes) => (bytes >= 1 << 20 ? `${(bytes / (1 << 20)).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`);
|
||||
const trust = (p) =>
|
||||
p.key ? `<span class="badge badge-signed" title="Every file is signed with the author's key">Signed</span>` : `<span class="badge badge-unsigned" title="The file is pinned by its checksum, not signed">Unsigned</span>`;
|
||||
const initial = (p) => escape((p.name || p.id).trim().charAt(0).toUpperCase());
|
||||
const icon = (p) =>
|
||||
https(p.icon) ? `<img class="mod-icon" src="${escape(p.icon)}" alt="" width="48" height="48" loading="lazy">` : `<span class="mod-icon" aria-hidden="true">${initial(p)}</span>`;
|
||||
|
||||
export function matches(p, kind, text) {
|
||||
if (kind !== "all" && p.kind !== kind) return false;
|
||||
const hay = `${p.id} ${p.name} ${p.summary} ${(p.authors || []).join(" ")}`.toLowerCase();
|
||||
return text.toLowerCase().split(/\s+/).filter(Boolean).every((w) => hay.includes(w));
|
||||
}
|
||||
|
||||
// The list: a row per project, newest version and kind on the right.
|
||||
export function listHtml(projects) {
|
||||
if (!projects.length) return `<p class="lede mod-empty">Nothing here yet. <a href="${SUBMIT}">Submit yours</a>.</p>`;
|
||||
return projects
|
||||
.map(
|
||||
(p) => `<a class="mod-row" href="/mods/${p.id}" data-kind="${escape(p.kind)}" data-search="${escape(`${p.id} ${p.name} ${p.summary} ${(p.authors || []).join(" ")}`.toLowerCase())}">
|
||||
${icon(p)}
|
||||
<span class="mod-text"><span class="mod-name">${escape(p.name)}</span><span class="mod-summary">${escape(p.summary || "")}</span></span>
|
||||
<span class="mod-side"><span class="badge">${escape(KIND_NAMES[p.kind] || p.kind)}</span><span class="mod-version">${escape(p.versions[0].version)} · ${escape((p.authors || []).join(", "))}</span></span>
|
||||
</a>`,
|
||||
)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
function installHtml(p, v) {
|
||||
const file = escape(v.file.name);
|
||||
const cli = `horizon-launcher mods install --source horizon ${p.id}`;
|
||||
const where = {
|
||||
mod: `put it in <code>horizon-mods/</code> beside <code>options.txt</code> in the game folder, then turn it on in the game: Options > Mods`,
|
||||
resourcepack: `put it in <code>resourcepacks/</code> beside <code>options.txt</code>, then turn it on in Options > Resource Packs`,
|
||||
modpack: `a modpack lists registry mods: install them one by one, or wait for the launcher to install modpacks`,
|
||||
shader: `Horizon's own shader packs aren't installed yet`,
|
||||
}[p.kind];
|
||||
return `<ol class="mod-steps">
|
||||
<li>In the launcher: <strong>Mods</strong>, pick <strong>Horizon</strong> beside Modrinth, find ${escape(p.name)} and press <strong>Install</strong>. It checks the file's checksum${p.key ? " and signature" : ""} first.</li>
|
||||
<li>From a terminal or an agent: <code>${escape(cli)}</code></li>
|
||||
<li>By hand: download <a href="${escape(https(v.file.url))}">${file}</a> (${size(v.file.size)}), check its SHA-256 below, and ${where}.</li>
|
||||
</ol>`;
|
||||
}
|
||||
|
||||
// GitHub's rule for a login: letters, digits and single dashes, at most 39.
|
||||
const LOGIN = /^(?!-)(?!.*--)[A-Za-z0-9-]{1,39}(?<!-)$/;
|
||||
|
||||
// Who publishes it: the GitHub accounts the registry checked when the project was submitted.
|
||||
export function ownersHtml(p) {
|
||||
const owners = (p.owners || []).filter((o) => LOGIN.test(o));
|
||||
if (!owners.length) return "";
|
||||
const links = owners
|
||||
.map((o) => `<a class="mod-owner" href="https://github.com/${o}"><img src="https://avatars.githubusercontent.com/${o}?s=48" alt="" width="24" height="24" loading="lazy">@${o}</a>`)
|
||||
.join(" ");
|
||||
return `<p class="meta mod-owners">Published by ${links}</p>`;
|
||||
}
|
||||
|
||||
// One project's page.
|
||||
export function projectHtml(p) {
|
||||
const v = p.versions[0];
|
||||
const caps = v.capabilities || [];
|
||||
const capsHtml = caps.length
|
||||
? `<ul class="mod-caps">${caps.map((c) => `<li>May ${escape(CAPABILITIES[c] || c)}</li>`).join("")}</ul>`
|
||||
: `<p>It asks for nothing beyond writing its own log.</p>`;
|
||||
const requires = (v.requires || []).length
|
||||
? `<h2 class="heading">Its mods</h2><ul class="mod-caps">${v.requires.map((r) => `<li><a href="/mods/${escape(r.id)}">${escape(r.id)}</a> ${escape(r.version)}</li>`).join("")}</ul>`
|
||||
: "";
|
||||
const versions = p.versions
|
||||
.map((x) => `<li><strong>${escape(x.version)}</strong> <span class="mod-version">${escape(x.published || "")} · for ${escape(x.game)}${x.api ? ` · API ${escape(x.api)}` : ""}</span>${x.changelog ? `<div class="prose">${markdown(x.changelog)}</div>` : ""}</li>`)
|
||||
.join("");
|
||||
return `<article class="mod-page" data-id="${escape(p.id)}">
|
||||
<header class="mod-head">${icon(p)}<div><p class="kicker"><span>${escape(KIND_NAMES[p.kind] || p.kind)}</span>${escape((p.authors || []).join(", "))}</p>${ownersHtml(p)}
|
||||
<h1 class="display page-title">${escape(p.name)}</h1><p class="lede">${escape(p.summary || "")}</p>
|
||||
<p class="mod-badges">${trust(p)} <span class="badge">${escape(p.license)}</span> <span class="badge">${escape(v.version)}</span>${v.side ? ` <span class="badge">${escape(v.side)}</span>` : ""}</p></div></header>
|
||||
${p.description ? `<div class="prose">${markdown(p.description)}</div>` : ""}
|
||||
${p.kind === "mod" ? `<h2 class="heading">What it may do</h2>${capsHtml}<p class="meta">Mods run in a sandbox with no file, network or clock access. The game refuses a mod whose code uses more than this list.</p>` : ""}
|
||||
${requires}
|
||||
<h2 class="heading">Install</h2>
|
||||
${installHtml(p, v)}
|
||||
<h2 class="heading">File</h2>
|
||||
<dl class="mod-file"><dt>Name</dt><dd><a href="${escape(https(v.file.url))}">${escape(v.file.name)}</a></dd><dt>Size</dt><dd>${size(v.file.size)}</dd><dt>SHA-256</dt><dd><code>${escape(v.file.sha256)}</code></dd>${p.key ? `<dt>Signing key</dt><dd><code>${escape(p.key)}</code></dd>` : ""}</dl>
|
||||
<h2 class="heading">Versions</h2>
|
||||
<ul class="mod-versions">${versions}</ul>
|
||||
<p class="mod-links">${https(p.source) ? `<a class="link-arrow" href="${escape(p.source)}">Source code<span aria-hidden="true">→</span></a>` : ""}
|
||||
<a class="link-arrow" href="${REGISTRY}/blob/main/mods/${escape(p.id)}.toml">Its entry in the registry<span aria-hidden="true">→</span></a>
|
||||
<a class="link-arrow" href="${REGISTRY}/issues/new?template=report.yml&title=${escape(p.id)}">Report it<span aria-hidden="true">→</span></a></p>
|
||||
</article>`;
|
||||
}
|
||||
|
||||
// /mods/submit: the form. Its script (mods-submit.js) signs in, then sends the page and the file to the service, which
|
||||
// checks the file and opens the pull request the reviewers read.
|
||||
const field = (name, label, input, hint = "") =>
|
||||
`<label class="mod-field" for="f-${name}"><span class="mod-label">${label}</span>${input}${hint ? `<span class="meta">${hint}</span>` : ""}</label>`;
|
||||
const text = (name, attrs = "") => `<input class="mod-search" id="f-${name}" name="${name}" ${attrs}>`;
|
||||
|
||||
export function submitHtml() {
|
||||
return `<p class="kicker"><span>Mods</span>Submit</p>
|
||||
<h1 class="display page-title">Submit to the registry</h1>
|
||||
<p class="lede">A mod, a modpack of registry mods, or a resource pack made for Horizon. The form checks the file and opens a pull request; a reviewer reads it, its source and the checks' report, and merging publishes it to this site and the launcher.</p>
|
||||
<div class="mod-auth" id="submit-auth" aria-live="polite">
|
||||
<p class="meta no-script">The form needs JavaScript. You can also <a href="${REGISTRY}">open a pull request by hand</a>.</p>
|
||||
</div>
|
||||
<form class="mod-form" id="submit-form" hidden>
|
||||
<fieldset><legend class="heading">The file</legend>
|
||||
${field("kind", "Kind", `<select class="mod-search" id="f-kind" name="kind">${KINDS.map(([k, label]) => `<option value="${k}"${k === "shader" ? " disabled" : ""}>${label.replace(/s$/, "")}${k === "shader" ? " (opens with Horizon's own shader format)" : ""}</option>`).join("")}</select>`)}
|
||||
${field("file", "File", `<input id="f-file" name="file" type="file" accept=".hmod,.hpack,.zip" required>`, "A .hmod, a .hpack or a resource pack .zip, at most 64 MB. Run <code>cargo horizon-mod check</code> on it first.")}
|
||||
${field("id", "Id", text("id", `required pattern="[a-z0-9_]{1,64}" placeholder="my_mod" autocomplete="off"`), "Its manifest's id: a-z, 0-9 and _. A resource pack's is yours to pick.")}
|
||||
${field("version", "Version", text("version", `required pattern="[A-Za-z0-9][A-Za-z0-9._\\-]{0,63}" placeholder="1.0.0"`))}
|
||||
${field("game", "For Minecraft", text("game", `required value="26.3"`))}
|
||||
${field("changelog", "What changed", `<textarea class="mod-search" id="f-changelog" name="changelog" rows="3"></textarea>`, "Markdown.")}
|
||||
</fieldset>
|
||||
<fieldset><legend class="heading">Its page</legend>
|
||||
${field("name", "Name", text("name", `required maxlength="64"`))}
|
||||
${field("summary", "Summary", text("summary", `required maxlength="160"`), "One line for the list.")}
|
||||
${field("description", "Description", `<textarea class="mod-search" id="f-description" name="description" rows="6"></textarea>`, "Markdown.")}
|
||||
${field("authors", "Authors", text("authors", `placeholder="Alice, Bob"`), "Separated by commas.")}
|
||||
${field("license", "Licence", text("license", `required placeholder="MIT"`), "An SPDX expression.")}
|
||||
${field("source", "Source code", text("source", `required type="url" pattern="https://.*" placeholder="https://github.com/you/your-mod"`), "Reviewers read it: the file must be built from it.")}
|
||||
${field("icon", "Icon", text("icon", `type="url" pattern="https://.*" placeholder="https://…/icon.png"`), "Optional, a square PNG.")}
|
||||
</fieldset>
|
||||
<fieldset><legend class="heading">Signature</legend>
|
||||
<p class="meta">Optional, and recommended: with your <a href="https://jedisct1.github.io/minisign/">minisign</a> key on the project, every later version must be signed with it, so nobody else can publish an update in your name.</p>
|
||||
${field("key", "Public key", text("key", `placeholder="RW…" autocomplete="off"`), "A new project's. Changing a published project's key is a pull request by hand.")}
|
||||
${field("signature", "Signature", `<input id="f-signature" name="signature" type="file" accept=".minisig">`, "The file's .minisig.")}
|
||||
</fieldset>
|
||||
<label class="mod-check"><input type="checkbox" id="f-mine" required> I made it, or I may publish it under this licence, and its source is at the address above.</label>
|
||||
<p class="mod-actions"><button class="button primary" type="submit" id="f-send">Submit for review</button></p>
|
||||
<div class="mod-result" id="submit-result" role="status" aria-live="polite"></div>
|
||||
</form>`;
|
||||
}
|
||||
|
||||
// The service's "entry" from the form's values (strings), as it reads it.
|
||||
export function entryFrom(v) {
|
||||
const optional = (x) => (x && x.trim() ? x.trim() : undefined);
|
||||
return {
|
||||
id: v.id.trim(),
|
||||
kind: v.kind,
|
||||
name: v.name.trim(),
|
||||
summary: v.summary.trim(),
|
||||
description: v.description || "",
|
||||
authors: (v.authors || "").split(",").map((a) => a.trim()).filter(Boolean),
|
||||
license: v.license.trim(),
|
||||
source: v.source.trim(),
|
||||
icon: optional(v.icon),
|
||||
key: optional(v.key),
|
||||
signature: optional(v.signature),
|
||||
version: v.version.trim(),
|
||||
game: v.game.trim(),
|
||||
changelog: v.changelog || "",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { CAPABILITIES, entryFrom, listHtml, matches, projectHtml, readIndex, submitHtml } from "./mods.js";
|
||||
|
||||
const project = (over = {}) => ({
|
||||
id: "coords_hud", kind: "mod", name: "Coordinates HUD", summary: "Where you are.", authors: ["Horizon"],
|
||||
license: "MIT", source: "https://example.org/src",
|
||||
versions: [{ version: "0.1.0", api: "0.1", side: "client", capabilities: ["game-read", "hud"], game: "26.3",
|
||||
file: { name: "coords_hud-0.1.0.hmod", url: "https://github.com/ludovic111/horizon-mods/releases/download/x/coords_hud-0.1.0.hmod", size: 438, sha256: "e".repeat(64) } }],
|
||||
...over,
|
||||
});
|
||||
|
||||
test("reads schema 1, keeps the kinds it knows and refuses a newer schema", () => {
|
||||
const index = { schema: 1, projects: [project(), project({ id: "map", kind: "world" }), project({ id: "Bad id" })] };
|
||||
assert.deepEqual(readIndex(index).map((p) => p.id), ["coords_hud"]);
|
||||
assert.equal(readIndex({ schema: 2, projects: [project()] }), null);
|
||||
assert.equal(readIndex(null), null);
|
||||
});
|
||||
|
||||
test("filters by kind and every word", () => {
|
||||
const p = project();
|
||||
assert.ok(matches(p, "all", "coordinates horizon"));
|
||||
assert.ok(matches(p, "mod", ""));
|
||||
assert.ok(!matches(p, "modpack", ""));
|
||||
assert.ok(!matches(p, "all", "zoom"));
|
||||
});
|
||||
|
||||
test("escapes what authors wrote and only links https addresses", () => {
|
||||
const evil = project({ name: "<script>x</script>", source: "javascript:alert(1)", summary: '"><img src=x onerror=alert(1)>' });
|
||||
const html = listHtml([evil]) + projectHtml(evil);
|
||||
assert.ok(!html.includes("<script>x"));
|
||||
assert.ok(!html.includes("<img src=x"));
|
||||
assert.ok(!html.includes("javascript:"));
|
||||
});
|
||||
|
||||
test("a mod's page says what it may do, as the game does", () => {
|
||||
const html = projectHtml(project());
|
||||
assert.ok(html.includes(`May ${CAPABILITIES["game-read"]}`));
|
||||
assert.ok(html.includes("Unsigned"));
|
||||
assert.ok(projectHtml(project({ key: "RWT" })).includes("Signed"));
|
||||
assert.ok(html.includes("horizon-launcher mods install --source horizon coords_hud"));
|
||||
});
|
||||
|
||||
test("the submit form sends what the service reads", () => {
|
||||
const html = submitHtml();
|
||||
for (const name of ["kind", "file", "id", "version", "game", "name", "summary", "license", "source", "key", "signature"]) {
|
||||
assert.ok(html.includes(`id="f-${name}"`), name);
|
||||
}
|
||||
assert.match(html, /<option value="shader" disabled>/);
|
||||
const entry = entryFrom({ id: " my_mod ", kind: "mod", name: "My mod", summary: "s", description: "", authors: "Alice, , Bob", license: "MIT", source: "https://x.test", icon: " ", key: "", signature: "", version: "1.0.0", game: "26.3", changelog: "" });
|
||||
assert.deepEqual(entry.authors, ["Alice", "Bob"]);
|
||||
assert.equal(entry.id, "my_mod");
|
||||
assert.equal(entry.icon, undefined);
|
||||
assert.equal(JSON.parse(JSON.stringify(entry)).key, undefined, "an empty key isn't sent");
|
||||
});
|
||||
|
||||
test("a project's page links its owners' GitHub profiles, and only valid logins", () => {
|
||||
const html = projectHtml(project({ owners: ["Stink-O", "bad login", "-x", "a--b", "ok\"><script>"] }));
|
||||
assert.ok(html.includes('href="https://github.com/Stink-O"'));
|
||||
assert.ok(html.includes("@Stink-O"));
|
||||
for (const bad of ["bad login", "github.com/-x", "a--b", "<script>"]) assert.ok(!html.includes(bad), bad);
|
||||
assert.ok(!projectHtml(project()).includes("Published by"));
|
||||
});
|
||||
@@ -826,3 +826,66 @@ code { border-radius: 0; background: var(--well); box-shadow: 0 0 0 1px var(--ou
|
||||
.hub-rows .row > a { grid-template-columns: var(--index) minmax(0, 1fr); }
|
||||
.hub-rows .row-meta { grid-column: 2; text-align: left; }
|
||||
}
|
||||
|
||||
/* The registry (/mods): a search and the kind filter, rows as panels, then a page per project. */
|
||||
.mod-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
|
||||
.mod-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-top: 32px; }
|
||||
.mod-tools .release-filter { margin-top: 0; }
|
||||
.mod-search {
|
||||
height: 36px; min-width: min(320px, 100%); padding: 0 12px; font: var(--text-ui) / 1 var(--sans); color: var(--ink);
|
||||
background: var(--well); border: var(--block-outline) solid var(--outline); border-radius: 0;
|
||||
}
|
||||
.mod-search:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
|
||||
.mod-list { display: grid; gap: 8px; }
|
||||
.mod-row {
|
||||
display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 14px 20px;
|
||||
background: var(--panel); border: var(--block-outline) solid var(--outline); box-shadow: var(--panel-edges); color: var(--ink); text-decoration: none;
|
||||
}
|
||||
.mod-row:hover { background: var(--raised); }
|
||||
.mod-row:hover .mod-name { color: var(--accent); }
|
||||
.mod-icon {
|
||||
display: grid; place-items: center; width: 48px; height: 48px; flex: none; image-rendering: pixelated;
|
||||
font: 600 22px / 1 var(--pixel); color: var(--ink); background: var(--well); box-shadow: 0 0 0 var(--block-outline) var(--outline);
|
||||
}
|
||||
.mod-text { display: grid; gap: 4px; min-width: 0; }
|
||||
.mod-name { font: 500 var(--text-heading) / 1.2 var(--pixel); }
|
||||
.mod-summary { color: var(--muted); font-size: var(--text-ui); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.mod-side { display: grid; justify-items: end; gap: 6px; }
|
||||
.mod-side .badge { margin-right: 0; }
|
||||
.mod-version { font: var(--text-micro) / 1.4 var(--mono); letter-spacing: var(--text-micro-tracking); color: var(--muted); }
|
||||
.mod-empty a { color: var(--accent); }
|
||||
.badge-signed { background: color-mix(in srgb, var(--success) 22%, var(--panel)); color: var(--ink); }
|
||||
.badge-unsigned { background: color-mix(in srgb, var(--warn) 24%, var(--panel)); color: var(--ink); }
|
||||
.mod-page { display: grid; gap: 16px; max-width: calc(var(--measure) + 240px); }
|
||||
.mod-page .heading { margin-top: 24px; }
|
||||
.mod-head { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 24px; align-items: start; }
|
||||
.mod-owners { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0 0; }
|
||||
.mod-owner { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.mod-owner img { border-radius: 50%; }
|
||||
.mod-head .mod-icon { width: 96px; height: 96px; font-size: 44px; }
|
||||
.mod-head .page-title { margin-top: 0; }
|
||||
.mod-badges { margin-top: 16px; }
|
||||
.mod-caps, .mod-steps, .mod-versions { display: grid; gap: 8px; padding-left: 20px; font-size: var(--text-ui); }
|
||||
.mod-caps li::marker, .mod-steps li::marker { color: var(--accent); }
|
||||
.mod-file { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; font-size: var(--text-ui); }
|
||||
.mod-file dt { color: var(--muted); }
|
||||
.mod-file code, .mod-steps code { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
|
||||
.mod-links { display: flex; flex-wrap: wrap; gap: 24px; margin-top: 24px; }
|
||||
/* /mods/submit */
|
||||
.mod-form { display: grid; gap: 24px; max-width: var(--measure); margin-top: 32px; }
|
||||
.mod-form fieldset { display: grid; gap: 16px; margin: 0; padding: 0; border: 0; }
|
||||
.mod-form legend { padding: 0; margin-bottom: 8px; }
|
||||
.mod-field { display: grid; gap: 6px; }
|
||||
.mod-label { font-size: var(--text-ui); font-weight: 500; }
|
||||
.mod-form .mod-search { width: 100%; }
|
||||
.mod-form textarea.mod-search { height: auto; padding: 10px 12px; line-height: 1.5; resize: vertical; }
|
||||
.mod-check { display: flex; gap: 10px; align-items: flex-start; font-size: var(--text-ui); }
|
||||
.mod-auth { margin-top: 24px; }
|
||||
.mod-error { color: var(--danger); font-size: var(--text-ui); }
|
||||
.js .no-script { display: none; }
|
||||
@media (max-width: 640px) {
|
||||
.mod-row { grid-template-columns: 40px minmax(0, 1fr); }
|
||||
.mod-side { grid-column: 2; justify-items: start; }
|
||||
.mod-icon { width: 40px; height: 40px; }
|
||||
.mod-head { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user