Hub: the roadmap at /data/roadmap.json and items at hub#<id>, as Kira reads them
Kira (kira #10-#14) fetches https://playhorizon.dev/data/roadmap.json and links items as <hub>#<id>: the JSON moves there (readable from any origin) with the announce flag, and each item's anchor is its id. Ids the page uses itself (tabs, sections, headings) are refused by the check; a test keeps every id of the page unique, which caught the overview's headings sharing ids with the roadmap's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// The hub page (/hub): its tabs (one per #hash, so /hub#roadmap and /hub#item-<id> can be linked), the
|
||||
// The hub page (/hub): its tabs (one per #hash, so /hub#roadmap and /hub#<item id> can be linked), the
|
||||
// Simple / Technical switch (remembered in localStorage), the area filter, and the live state of every
|
||||
// linked issue and pull request, refreshed from GitHub's public API. Without JavaScript, every tab reads
|
||||
// one after the other with what was baked at build time.
|
||||
@@ -30,7 +30,7 @@ function choose(tab, { focus = false, push = false } = {}) {
|
||||
if (focus) tab.focus();
|
||||
if (push && location.hash !== `#${panelOf(tab).id}`) history.replaceState(null, "", `#${panelOf(tab).id}`);
|
||||
}
|
||||
// "#roadmap" opens its tab; "#item-x" or "#help-wanted" opens the tab holding it and scrolls there.
|
||||
// "#roadmap" opens its tab; "#<item id>" or "#help-wanted" opens the tab holding it and scrolls there.
|
||||
function follow() {
|
||||
const target = location.hash && document.getElementById(decodeURIComponent(location.hash.slice(1)));
|
||||
const tab = tabs.find((t) => target && (panelOf(t) === target || panelOf(t).contains(target))) || tabs[0];
|
||||
@@ -116,4 +116,4 @@ async function refresh() {
|
||||
setUpTheme();
|
||||
setUpMenu();
|
||||
follow();
|
||||
refresh().then(() => location.hash.startsWith("#item-") && follow());
|
||||
refresh().then(() => data.roadmap.items.some((i) => `#${i.id}` === location.hash) && follow());
|
||||
|
||||
+11
-11
@@ -86,7 +86,7 @@ const areaName = (roadmap, id) => roadmap.areas.find((a) => a.id === id)?.name |
|
||||
export function itemHtml(item, roadmap, live) {
|
||||
const done = item.status === "shipped";
|
||||
const state = done ? "" : progress(item, live);
|
||||
return `<article class="hub-item" id="item-${escape(item.id)}" data-area="${escape(item.area)}" data-item="${escape(item.id)}">
|
||||
return `<article class="hub-item" id="${escape(item.id)}" data-area="${escape(item.area)}" data-item="${escape(item.id)}">
|
||||
<p class="hub-item-meta"><span class="badge">${escape(areaName(roadmap, item.area))}</span>${done ? `<span class="badge badge-game">${escape(item.shipped_in)}</span>` : ""}${item.ongoing ? `<span class="hub-ongoing">Ongoing</span>` : ""}</p>
|
||||
<h3 class="hub-item-title">${escape(item.title)}</h3>
|
||||
<p class="hub-plain">${inline(item.plain)}</p>
|
||||
@@ -137,25 +137,25 @@ export function overviewHtml(roadmap, live = new Map()) {
|
||||
const focus = roadmap.items.filter((i) => i.focus);
|
||||
const next = roadmap.items.filter((i) => i.status === "next");
|
||||
const shipped = roadmap.items.filter((i) => i.status === "shipped").slice(0, 3);
|
||||
const row = (item, i, meta) => `<li class="row"><a href="#item-${escape(item.id)}" data-goto="roadmap"><span class="row-index">${String(i + 1).padStart(2, "0")}</span><span class="hub-row-body"><span class="hub-row-title">${escape(item.title)}</span><span class="hub-plain">${inline(item.plain)}</span><span class="hub-dev">${inline(item.dev)}</span></span><span class="row-meta">${escape(meta(item))}</span></a></li>`;
|
||||
const row = (item, i, meta) => `<li class="row"><a href="#${escape(item.id)}" data-goto="roadmap"><span class="row-index">${String(i + 1).padStart(2, "0")}</span><span class="hub-row-body"><span class="hub-row-title">${escape(item.title)}</span><span class="hub-plain">${inline(item.plain)}</span><span class="hub-dev">${inline(item.dev)}</span></span><span class="row-meta">${escape(meta(item))}</span></a></li>`;
|
||||
return `<div class="hub-today">
|
||||
<p class="hub-plain hub-lead">${inline(o.today_plain)}</p>
|
||||
<p class="hub-dev hub-lead">${inline(o.today_dev)}</p>
|
||||
</div>
|
||||
<section class="hub-block" aria-labelledby="h-focus">
|
||||
<h2 class="title" id="h-focus">Being done now</h2>
|
||||
<section class="hub-block" aria-labelledby="h-ov-focus">
|
||||
<h2 class="title" id="h-ov-focus">Being done now</h2>
|
||||
<ol class="index hub-rows">${focus.map((item, i) => row(item, i, (x) => progress(x, live))).join("")}</ol>
|
||||
</section>
|
||||
<section class="hub-block" aria-labelledby="h-next">
|
||||
<h2 class="title" id="h-next">Next</h2>
|
||||
<section class="hub-block" aria-labelledby="h-ov-next">
|
||||
<h2 class="title" id="h-ov-next">Next</h2>
|
||||
<ol class="index hub-rows">${next.map((item, i) => row(item, i, (x) => areaName(roadmap, x.area))).join("")}</ol>
|
||||
</section>
|
||||
<section class="hub-block" aria-labelledby="h-shipped">
|
||||
<h2 class="title" id="h-shipped">Recently shipped</h2>
|
||||
<section class="hub-block" aria-labelledby="h-ov-shipped">
|
||||
<h2 class="title" id="h-ov-shipped">Recently shipped</h2>
|
||||
<ol class="index hub-rows">${shipped.map((item, i) => row(item, i, (x) => `In ${x.shipped_in}`)).join("")}</ol>
|
||||
</section>
|
||||
<section class="hub-block hub-help" aria-labelledby="h-help">
|
||||
<h2 class="title" id="h-help">How to help</h2>
|
||||
<section class="hub-block hub-help" aria-labelledby="h-ov-help">
|
||||
<h2 class="title" id="h-ov-help">How to help</h2>
|
||||
<p class="hub-plain">${inline(o.help_plain)}</p>
|
||||
<p class="hub-dev">${inline(o.help_dev)}</p>
|
||||
<p class="hub-actions"><a class="button primary" href="#contribute" data-goto="contribute">Contribute</a><a class="button secondary" href="#help-wanted" data-goto="roadmap">Help wanted</a></p>
|
||||
@@ -168,7 +168,7 @@ export function helpWantedHtml(roadmap) {
|
||||
.filter((i) => i.status === "help-wanted")
|
||||
.map((item, i) => {
|
||||
const first = (item.links || []).map(number).find(Boolean);
|
||||
const href = first ? issueUrl(first) : `#item-${item.id}`;
|
||||
const href = first ? issueUrl(first) : `#${item.id}`;
|
||||
return `<li class="row"><a href="${escape(href)}"><span class="row-index">${String(i + 1).padStart(2, "0")}</span><span class="hub-row-body"><span class="hub-row-title">${escape(item.title)}</span><span class="hub-plain">${inline(item.plain)}</span><span class="hub-dev">${inline(item.dev)}</span></span><span class="row-meta">${first ? `#${first}` : ""}</span></a></li>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
@@ -33,7 +33,7 @@ test("an item's progress counts its pull requests and issues", () => {
|
||||
test("the roadmap renders every item once, with both texts, in its status's section", () => {
|
||||
const html = roadmapHtml(roadmap);
|
||||
for (const item of roadmap.items) {
|
||||
assert.equal(html.split(`id="item-${item.id}"`).length, 2, item.id);
|
||||
assert.equal(html.split(`id="${item.id}"`).length, 2, item.id);
|
||||
}
|
||||
assert.ok(html.indexOf('id="now"') < html.indexOf('id="next"'));
|
||||
assert.ok(html.includes('class="hub-plain"') && html.includes('class="hub-dev"'));
|
||||
@@ -41,8 +41,15 @@ test("the roadmap renders every item once, with both texts, in its status's sect
|
||||
assert.ok(html.includes(`>${roadmap.items.find((i) => i.status === "shipped").shipped_in}<`));
|
||||
});
|
||||
|
||||
test("an item is its own anchor (hub#<id>, as Kira links it) and takes no other id of the page", () => {
|
||||
const page = readFileSync(new URL("./hub.html", import.meta.url), "utf8") + roadmapHtml(roadmap) + overviewHtml(roadmap);
|
||||
const ids = [...page.matchAll(/ id="([^"]+)"/g)].map((m) => m[1]);
|
||||
assert.deepEqual(ids.filter((id, i) => ids.indexOf(id) !== i), []);
|
||||
for (const item of roadmap.items) assert.ok(ids.includes(item.id), item.id);
|
||||
});
|
||||
|
||||
test("the overview lists the focus items and never nests links", () => {
|
||||
const html = overviewHtml(roadmap);
|
||||
for (const item of roadmap.items.filter((i) => i.focus)) assert.ok(html.includes(`href="#item-${item.id}"`), item.id);
|
||||
for (const item of roadmap.items.filter((i) => i.focus)) assert.ok(html.includes(`href="#${item.id}"`), item.id);
|
||||
for (const row of html.match(/<li class="row">[\s\S]*?<\/li>/g)) assert.equal(row.split("<a ").length, 2, row);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user