// 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 ? `Signed` : `Unsigned`;
const initial = (p) => escape((p.name || p.id).trim().charAt(0).toUpperCase());
const icon = (p) =>
https(p.icon) ? `` : `${initial(p)}`;
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 `
`;
return projects
.map(
(p) => `
${icon(p)}
${escape(p.name)}${escape(p.summary || "")}${escape(KIND_NAMES[p.kind] || p.kind)}${escape(p.versions[0].version)} · ${escape((p.authors || []).join(", "))}`,
)
.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 horizon-mods/ beside options.txt in the game folder, then turn it on in the game: Options > Mods`,
resourcepack: `put it in resourcepacks/ beside options.txt, 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 `
In the launcher: Mods, pick Horizon beside Modrinth, find ${escape(p.name)} and press Install. It checks the file's checksum${p.key ? " and signature" : ""} first.
From a terminal or an agent: ${escape(cli)}
By hand: download ${file} (${size(v.file.size)}), check its SHA-256 below, and ${where}.
`;
}
// GitHub's rule for a login: letters, digits and single dashes, at most 39.
const LOGIN = /^(?!-)(?!.*--)[A-Za-z0-9-]{1,39}(? LOGIN.test(o));
if (!owners.length) return "";
const links = owners
.map((o) => `@${o}`)
.join(" ");
return `
Published by ${links}
`;
}
// One project's page.
export function projectHtml(p) {
const v = p.versions[0];
const caps = v.capabilities || [];
const capsHtml = caps.length
? `
`;
}
// /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 = "") =>
``;
const text = (name, attrs = "") => ``;
export function submitHtml() {
return `
ModsSubmit
Submit to the registry
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.
First time? Publish a mod walks through building, checking and signing the file, and Make a mod starts from the beginning.