Website: /mods, Horizon's registry of mods, modpacks and resource packs
The list (search, a filter per kind) and a page per project: what a mod may do in the game's own words, Signed or Unsigned, how to install it from the launcher, the CLI or by hand, its file, SHA-256 and versions, and links to its source, its registry entry and the report form. Baked from the published index at build time (HORIZON_MOD_INDEX for a test index) and refreshed by the page; Caddy serves /mods/<id> from its baked page, else the list page, which shows a project published since. 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,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,110 @@
|
||||
// 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 = `${REGISTRY}#submit`;
|
||||
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>`;
|
||||
}
|
||||
|
||||
// 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>
|
||||
<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>`;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { CAPABILITIES, listHtml, matches, projectHtml, readIndex } 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"));
|
||||
});
|
||||
@@ -741,3 +741,51 @@ code { border-radius: 0; background: var(--well); box-shadow: 0 0 0 1px var(--ou
|
||||
.release-detail { padding-left: 0; margin-left: 0; }
|
||||
.machine { padding: 16px; }
|
||||
}
|
||||
|
||||
/* 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-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; }
|
||||
@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