Registry: show who publishes a project, linked to their GitHub profile

The index already carries each project's owners (the GitHub accounts the
registry checked at submission), but neither the website nor the launcher
showed them. The project page now says "Published by @login" with the
avatar and a link to the profile; the launcher adds an @login link per
owner. Only strings that are valid GitHub logins become links.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-25 16:07:46 +01:00
parent bd591f9857
commit 0eb475152e
5 changed files with 66 additions and 3 deletions
+22 -2
View File
@@ -190,6 +190,18 @@ fn version_of(index: &Index, p: &index::Project, v: &index::Version) -> Version
}
}
/// A GitHub login as GitHub allows it (letters, digits, single dashes, at most 39), so an index
/// entry can't turn a link into something else.
fn github_login(login: &str) -> bool {
(1..=39).contains(&login.len())
&& login
.bytes()
.all(|b| b.is_ascii_alphanumeric() || b == b'-')
&& !login.starts_with('-')
&& !login.ends_with('-')
&& !login.contains("--")
}
/// The words of a query found in a project's id, name, summary or authors.
fn matches(p: &index::Project, text: &str) -> bool {
let hay = format!("{} {} {} {}", p.id, p.name, p.summary, p.authors.join(" ")).to_lowercase();
@@ -277,9 +289,14 @@ impl Source for Registry {
body.push_str(&format!("- {} {}{may}\n", m.name, w.version));
}
}
// Who publishes it: the GitHub accounts the registry checked at submission.
let owners = p.owners.iter().filter(|o| github_login(o)).map(|o| Link {
label: format!("@{o}"),
url: format!("https://github.com/{o}"),
});
Ok(Details {
body,
links: vec![
links: [
Link {
label: "Source".into(),
url: p.source.clone(),
@@ -292,7 +309,10 @@ impl Source for Registry {
label: "Report".into(),
url: format!("{REPORT}&title={}", p.id),
},
],
]
.into_iter()
.chain(owners)
.collect(),
authors: p.authors.clone(),
published: p
.versions
+19
View File
@@ -143,3 +143,22 @@ fn registry_versions_run_when_made_for_this_game() {
.collect();
assert_eq!(pick(Kind::Mod, &versions, false).unwrap().number, "0.1.0");
}
#[test]
fn owner_links_only_take_github_logins() {
for ok in ["Stink-O", "ludovic111", "a"] {
assert!(github_login(ok), "{ok}");
}
for bad in [
"",
"-x",
"x-",
"a--b",
"bad login",
"a/b",
"x?y=1",
&"a".repeat(40),
] {
assert!(!github_login(bad), "{bad}");
}
}
+14 -1
View File
@@ -79,6 +79,19 @@ function installHtml(p, v) {
</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];
@@ -93,7 +106,7 @@ export function projectHtml(p) {
.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>
<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>` : ""}
+8
View File
@@ -53,3 +53,11 @@ test("the submit form sends what the service reads", () => {
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"));
});
+3
View File
@@ -759,6 +759,9 @@ code { border-radius: 0; background: var(--well); box-shadow: 0 0 0 1px var(--ou
.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; }