Hub: journal.json in the flat format Kira reads, at /data/journal.json
One entry per merged pull request (with its roadmap item), game or launcher release, shipped roadmap item (post and announce) and weekly summary, newest first, ids stable forever: the feed kira's src/journal.js posts to #updates and X. The journal's item links are hub#<id>; the board's and the journal's ids are reserved too, and the page-wide unique-id test covers every tab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -71,7 +71,7 @@
|
||||
</div>
|
||||
|
||||
<div class="hub-panel" role="tabpanel" id="journal" aria-labelledby="tab-journal">
|
||||
<p class="hub-intro">Every release with what it changed, grouped by roadmap item in Technical, and a summary of each week. Also as <a href="/hub/journal.json">journal.json</a>.</p>
|
||||
<p class="hub-intro">Every release with what it changed, grouped by roadmap item in Technical, and a summary of each week. Also as <a href="/data/journal.json">journal.json</a>.</p>
|
||||
<div class="hub-journal" data-journal>
|
||||
{{HUB_JOURNAL}}
|
||||
</div>
|
||||
|
||||
+63
-16
@@ -319,19 +319,66 @@ export function journalFrom(releases, list, roadmap) {
|
||||
return entries.sort((a, b) => b.date.localeCompare(a.date)).slice(0, ENTRIES);
|
||||
}
|
||||
|
||||
// /hub/journal.json: the journal for Kira's #updates and posts elsewhere, with each shipped item's short text.
|
||||
export function journalJson(entries, roadmap, generated = new Date().toISOString()) {
|
||||
const item = (id) => {
|
||||
const i = roadmap.items.find((x) => x.id === id);
|
||||
return i && { id: i.id, title: i.title, plain: i.plain, post: i.post || i.plain };
|
||||
};
|
||||
return {
|
||||
format: "horizon-journal",
|
||||
version: 1,
|
||||
generated,
|
||||
url: JOURNAL_URL,
|
||||
entries: entries.map((e) => ({ ...e, items: [...new Set(e.changes.map((c) => c.item).filter(Boolean))].map(item).filter(Boolean), shipped: e.shipped.map(item).filter(Boolean) })),
|
||||
};
|
||||
const HUB = "https://playhorizon.dev/hub";
|
||||
const FEED = 300;
|
||||
|
||||
// /data/journal.json, which Kira reads for #updates and X (kira's src/journal.js): one flat entry per merged pull
|
||||
// request, release, shipped roadmap item and weekly summary, newest first. An entry's id never changes: Kira posts
|
||||
// each id once. Shipped items carry `post` (at most 240 characters, tools/roadmap.py checks) and `announce`.
|
||||
export function journalJson(releases, list, roadmap, generated = new Date().toISOString()) {
|
||||
const items = new Map(roadmap.items.map((i) => [i.id, i]));
|
||||
const ours = releases.filter((r) => !r.draft && (isGame(r.tag_name) || isLauncher(r.tag_name)));
|
||||
const published = new Map(ours.map((r) => [r.tag_name, r.published_at || ""]));
|
||||
const merges = list
|
||||
.filter((i) => i.kind === "pr" && i.state === "merged")
|
||||
.map((pr) => ({ pr, item: itemOf(pr, roadmap) }))
|
||||
// What players see, and anything that moves a roadmap item.
|
||||
.filter(({ pr, item }) => item || !pr.labels.includes("skip-release"))
|
||||
.map(({ pr, item }) => ({
|
||||
id: `pr-${pr.n}`,
|
||||
kind: "merge",
|
||||
date: pr.at,
|
||||
title: pr.title,
|
||||
url: pr.url,
|
||||
number: pr.n,
|
||||
...(item ? { item, item_title: items.get(item)?.title } : {}),
|
||||
}));
|
||||
const released = ours.map((r) => ({
|
||||
id: `release-${r.tag_name}`,
|
||||
kind: "release",
|
||||
date: r.published_at || "",
|
||||
title: r.name || r.tag_name,
|
||||
plain: parts(r).line,
|
||||
url: r.html_url,
|
||||
tag: r.tag_name,
|
||||
}));
|
||||
const shipped = roadmap.items
|
||||
.filter((i) => i.status === "shipped")
|
||||
.map((i) => ({
|
||||
id: `shipped-${i.id}`,
|
||||
kind: "shipped",
|
||||
date: published.get(i.shipped_in) || generated,
|
||||
title: i.title,
|
||||
plain: i.plain,
|
||||
url: `${HUB}#${i.id}`,
|
||||
item: i.id,
|
||||
item_title: i.title,
|
||||
shipped_in: i.shipped_in,
|
||||
post: i.post || i.plain,
|
||||
announce: Boolean(i.announce),
|
||||
}));
|
||||
// A week's summary is dated at the end of its week, after that week's releases.
|
||||
const weekly = (roadmap.journal || []).map((w) => ({
|
||||
id: `weekly-${w.week}`,
|
||||
kind: "weekly",
|
||||
date: new Date(Date.parse(w.date) + 7 * 864e5 - 1000).toISOString(),
|
||||
title: w.title,
|
||||
plain: w.plain,
|
||||
dev: w.dev,
|
||||
url: `${HUB}#week-${w.week}`,
|
||||
}));
|
||||
const entries = [...merges, ...released, ...shipped, ...weekly].sort((a, b) => b.date.localeCompare(a.date) || a.id.localeCompare(b.id));
|
||||
return { format: "horizon-journal", version: 2, generated, url: `${HUB}#journal`, entries: entries.slice(0, FEED) };
|
||||
}
|
||||
|
||||
const KIND = { release: "Game", launcher: "Launcher", merged: "Merged", week: "This week" };
|
||||
@@ -349,7 +396,7 @@ function changesHtml(entry, roadmap) {
|
||||
const dev = `<div class="hub-dev">${order
|
||||
.map((id) => {
|
||||
const item = roadmap.items.find((i) => i.id === id);
|
||||
return `<p class="hub-group">${item ? `<a href="#item-${escape(id)}">${escape(item.title)}</a>` : "Other changes"}</p><ul class="hub-changes">${groups.get(id).map(line).join("")}</ul>`;
|
||||
return `<p class="hub-group">${item ? `<a href="#${escape(id)}">${escape(item.title)}</a>` : "Other changes"}</p><ul class="hub-changes">${groups.get(id).map(line).join("")}</ul>`;
|
||||
})
|
||||
.join("")}</div>`;
|
||||
return simple + dev;
|
||||
@@ -364,8 +411,8 @@ export function journalHtml(entries, roadmap) {
|
||||
<p class="hub-entry-meta"><span class="badge${e.kind === "release" ? " badge-game" : e.kind === "launcher" ? " badge-launcher" : ""}">${KIND[e.kind]}</span><time datetime="${escape(e.date)}">${escape(e.date.slice(0, 10))}</time></p>
|
||||
<h3 class="hub-entry-title">${e.url ? `<a href="${escape(e.url)}">${escape(e.title)}</a>` : escape(e.title)}</h3>
|
||||
${e.kind === "week" ? `<p class="hub-plain">${inline(e.plain)}</p><p class="hub-dev">${inline(e.dev.replace(/(^|[^\w[/`])#(\d+)\b/g, (_, b, n) => `${b}[#${n}](${issueUrl(n)})`))}</p>` : ""}
|
||||
${shipped.length ? `<p class="hub-shipped">Shipped: ${shipped.map((i) => `<a href="#item-${escape(i.id)}">${escape(i.title)}</a>`).join(", ")}</p>` : ""}
|
||||
${items.length ? `<p class="hub-entry-items hub-plain">${items.map((i) => `<a class="hub-link" href="#item-${escape(i.id)}">${escape(i.title)}</a>`).join("")}</p>` : ""}
|
||||
${shipped.length ? `<p class="hub-shipped">Shipped: ${shipped.map((i) => `<a href="#${escape(i.id)}">${escape(i.title)}</a>`).join(", ")}</p>` : ""}
|
||||
${items.length ? `<p class="hub-entry-items hub-plain">${items.map((i) => `<a class="hub-link" href="#${escape(i.id)}">${escape(i.title)}</a>`).join("")}</p>` : ""}
|
||||
${changesHtml(e, roadmap)}
|
||||
</article>`;
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { boardFrom, fixesIn, itemOf, journalFrom, journalHtml, journalJson, overviewHtml, progress, roadmapHtml, slimIssue } from "./hub.js";
|
||||
import { boardFrom, boardHtml, fixesIn, itemOf, journalFrom, journalHtml, journalJson, overviewHtml, progress, roadmapHtml, slimIssue } from "./hub.js";
|
||||
|
||||
const roadmap = JSON.parse(readFileSync(new URL("../data/roadmap.json", import.meta.url), "utf8"));
|
||||
|
||||
@@ -42,7 +42,11 @@ test("the roadmap renders every item once, with both texts, in its status's sect
|
||||
});
|
||||
|
||||
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 week = { week: "2030-01", date: "2029-12-31", title: "A week", plain: "p", dev: "d" };
|
||||
const release = { tag_name: "v0.2.2", name: "0.2.2", published_at: "2030-01-02T00:00:00Z", html_url: "u", body: "" };
|
||||
const journal = journalHtml(journalFrom([release], [], { ...roadmap, journal: [week] }), roadmap);
|
||||
const board = boardHtml(boardFrom([], roadmap), roadmap);
|
||||
const page = readFileSync(new URL("./hub.html", import.meta.url), "utf8") + roadmapHtml(roadmap) + overviewHtml(roadmap) + board + journal;
|
||||
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);
|
||||
@@ -91,10 +95,45 @@ test("the journal groups a release's changes by roadmap item and lists what awai
|
||||
assert.deepEqual(entries.map((e) => e.id), ["next-release", "v0.2.2", "launcher@0.2.1"]);
|
||||
assert.deepEqual(entries[0].changes.map((c) => [c.prs, c.item]), [[[1788], "discord-presence"]]);
|
||||
assert.deepEqual(entries[1].changes.map((c) => [c.section, c.text, c.item]), [["new", "Discord Rich Presence", "discord-presence"], ["fixed", "A fix", null]]);
|
||||
const json = journalJson(entries, roadmap, "now");
|
||||
assert.equal(json.format, "horizon-journal");
|
||||
assert.equal(json.entries[1].items[0].post.length <= 240, true);
|
||||
const html = journalHtml(entries, roadmap);
|
||||
assert.ok(html.includes('href="#item-discord-presence"'));
|
||||
assert.ok(html.includes('href="#discord-presence"'));
|
||||
assert.ok(html.includes("And 1 fix."));
|
||||
});
|
||||
|
||||
test("journal.json is the flat feed Kira reads: merges, releases, shipped items, weeks, ids that never change", () => {
|
||||
const releases = [
|
||||
{ tag_name: "v0.2.48", name: "Horizon 0.2.48", published_at: "2030-01-02T00:00:00Z", html_url: "https://github.com/ludovic111/horizon/releases/tag/v0.2.48", body: "### New\n- Packs (#1)\n" },
|
||||
{ tag_name: "nightly-1", name: "Nightly", published_at: "2030-01-03T00:00:00Z", html_url: "u", body: "" },
|
||||
];
|
||||
const list = [
|
||||
pr(1788, { state: "closed", pull_request: { merged_at: "2030-01-04T00:00:00Z" }, html_url: "https://github.com/ludovic111/horizon/pull/1788" }),
|
||||
pr(7, { state: "closed", pull_request: { merged_at: "2030-01-04T00:00:00Z" }, labels: [{ name: "skip-release" }] }),
|
||||
pr(8, { state: "closed", pull_request: { merged_at: "2030-01-04T00:00:00Z" }, labels: [{ name: "skip-release" }, { name: "roadmap:lean-code" }] }),
|
||||
pr(9),
|
||||
].map(slimIssue);
|
||||
const week = { week: "2030-01", date: "2029-12-31", title: "A week", plain: "p", dev: "d" };
|
||||
const feed = journalJson(releases, list, { ...roadmap, journal: [week] }, "2030-01-05T00:00:00Z");
|
||||
const byId = new Map(feed.entries.map((e) => [e.id, e]));
|
||||
// A merged pull request, with its roadmap item; skip-release ones only when they move an item; open ones never.
|
||||
assert.deepEqual(byId.get("pr-1788"), { id: "pr-1788", kind: "merge", date: "2030-01-04T00:00:00Z", title: "PR 1788", url: "https://github.com/ludovic111/horizon/pull/1788", number: 1788, item: "discord-presence", item_title: "Discord Rich Presence" });
|
||||
assert.ok(!byId.has("pr-7") && byId.get("pr-8").item === "lean-code" && !byId.has("pr-9"));
|
||||
// Game and launcher releases only.
|
||||
assert.equal(byId.get("release-v0.2.48").tag, "v0.2.48");
|
||||
assert.ok(!byId.has("release-nightly-1"));
|
||||
// Every shipped item, dated by its release when the feed has it, with its post and the announce flag.
|
||||
const shipped = roadmap.items.filter((i) => i.status === "shipped");
|
||||
for (const item of shipped) {
|
||||
const e = byId.get(`shipped-${item.id}`);
|
||||
assert.equal(e.kind, "shipped");
|
||||
assert.equal(e.url, `https://playhorizon.dev/hub#${item.id}`);
|
||||
assert.ok(e.post.length <= 240 && typeof e.announce === "boolean", item.id);
|
||||
}
|
||||
assert.equal(byId.get("shipped-server-resource-packs").date, "2030-01-02T00:00:00Z");
|
||||
assert.equal(byId.get("weekly-2030-01").date, "2030-01-06T23:59:59.000Z");
|
||||
// Newest first; every entry has what Kira needs, and links only where Kira shows them.
|
||||
assert.deepEqual(feed.entries.map((e) => e.date), feed.entries.map((e) => e.date).sort().reverse());
|
||||
for (const e of feed.entries) {
|
||||
assert.ok(e.id && ["merge", "release", "weekly", "shipped"].includes(e.kind) && e.date && e.title, e.id);
|
||||
assert.match(e.url, /^https:\/\/(github\.com|playhorizon\.dev)\//, e.id);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user