Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/web/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,15 @@ function changelogCatOf(rawLine) {
// keep the stale paint; the cache keeps its old timestamp, so the next visit retries
}).then(function () { blogRefreshBusy = false; });
}
// Per-post discussion thread: the thread number is data, not inference — it reaches
// the client as item.discussion once the server-side passthrough lands (separate PR,
// see PR body) and the pipeline records a number for the post. Exact direct link only;
// a post without a recorded number simply shows no button (no guessed search URL).
function blogDiscussionUrl(item) {
return (typeof item.discussion === "number" && item.discussion > 0)
? "https://github.com/ranxianglei/billion-context/discussions/" + item.discussion
: null;
}
async function loadBlog(sub) {
const host = $("bl-list");
if (!host) return;
Expand Down Expand Up @@ -985,7 +994,13 @@ function changelogCatOf(rawLine) {
const kindLabel = item.kind === "post" ? t("bl.kind_post") : t("bl.kind_article");
const title = zhOn && item.titleZh ? item.titleZh : (item.title || "");
const html = zhOn ? (item.htmlZh || item.html || "") : (item.html || "");
host.innerHTML = offlineNote + '<div class="card"><div class="card-b"><span class="mono bl-date">' + escapeHtml(item.date || "\u2014") + '</span><span class="badge">' + escapeHtml(kindLabel) + '</span><a href="#/blog" class="bl-back">' + escapeHtml(t("bl.back")) + "</a></div>"
const dUrl = blogDiscussionUrl(item);
const commentLink = dUrl ? '<a class="bl-back" href="' + dUrl + '" target="_blank" rel="noopener">' + escapeHtml(t("bl.comment")) + "</a>" : "";
// Per-article language pin: ?lang= outranks the saved UI language (#2321), so plain
// links double as an in-page EN|中文 toggle. Labels stay self-describing on purpose.
const subHref = "#/blog/" + encodeURIComponent(String(item.id));
const langToggle = '<a class="bl-back" href="?lang=en' + subHref + '">EN</a> <a class="bl-back" href="?lang=zh' + subHref + '">\u4e2d\u6587</a>';
host.innerHTML = offlineNote + '<div class="card"><div class="card-b"><span class="mono bl-date">' + escapeHtml(item.date || "\u2014") + '</span><span class="badge">' + escapeHtml(kindLabel) + '</span><a href="#/blog" class="bl-back">' + escapeHtml(t("bl.back")) + "</a> " + langToggle + " " + commentLink + "</div>"
+ '<h3 class="bl-h">' + escapeHtml(title) + "</h3>"
+ '<div class="card-b post-body">' + html + "</div></div>";
return;
Expand Down
2 changes: 2 additions & 0 deletions src/web/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"bl.kind_article": "长文",
"bl.empty": "这个版本还没内置文章。",
"bl.back": "← 全部文章",
"bl.comment": "去 GitHub 评论",
"bl.nf": "文章不存在或已被移除。",
"bl.offline": "上次拉取未完成,显示的是缓存内容(上次成功拉取或包内文章)。",
"nav.connect": "接入",
Expand Down Expand Up @@ -762,6 +763,7 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"bl.kind_article": "Article",
"bl.empty": "No bundled articles in this build.",
"bl.back": "\u2190 All articles",
"bl.comment": "Comment on GitHub",
"bl.nf": "Article not found or removed from this build.",
"bl.offline": "Last refresh did not finish — showing cached content (the last good pull or bundled articles).",
"nav.connect": "Connect",
Expand Down
15 changes: 14 additions & 1 deletion tests/web-blog-route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const mkHarnessEl = (): HarnessEl => ({
querySelectorAll: () => [], querySelector: () => null,
});

const FEED = { items: [{ id: "demo", kind: "post", date: "2026-10-08", title: "Demo post", titleZh: "演示", excerpt: "ex", html: "<p>hi</p>", htmlZh: "<p>你好</p>" }] };
const FEED = { items: [{ id: "demo", kind: "post", date: "2026-10-08", title: "Demo post", titleZh: "演示", excerpt: "ex", html: "<p>hi</p>", htmlZh: "<p>你好</p>", discussion: 123 }] };

// #4957: blog slugs keep whatever the filename carried after the date prefix
// (blogfeed.ts strips only `YYYY-MM-DD_`), so ids can contain dots, spaces and
Expand Down Expand Up @@ -113,6 +113,19 @@ test("#/blog/<slug> renders that single article with a back link", async () => {
const list = r.els.get("bl-list")!;
assert.ok(list.innerHTML.includes("post-body") && (list.innerHTML.includes("<p>hi</p>") || list.innerHTML.includes("\u4f60\u597d</p>")), "article body rendered (locale-twin aware)");
assert.ok(list.innerHTML.includes('<a href="#/blog" class="bl-back">'), "back link to the index present");
// #5396 final form: exact discussion link built from the manifest-recorded number
// (item.discussion) — no search guesswork; plus the in-page EN|中文 language pins.
assert.ok(list.innerHTML.includes('href="https://github.com/ranxianglei/billion-context/discussions/123" target="_blank" rel="noopener"'), "exact discussion-thread link from the recorded number");
assert.ok(list.innerHTML.includes("?lang=en#/blog/demo") && list.innerHTML.includes("?lang=zh#/blog/" + encodeURIComponent("demo")), "in-page language pins present");
assert.ok(list.innerHTML.includes("\u4e2d\u6587</a>"), "Chinese toggle label rendered");
});

test("#/blog/<slug> without a recorded discussion number shows no thread button", async () => {
const feed = { items: [{ id: "plain", kind: "post", date: "2026-10-08", title: "Plain", excerpt: "ex", html: "<p>p</p>" }] };
const r = await runClient("#/blog/plain", feed);
const list = r.els.get("bl-list")!;
assert.ok(list.innerHTML.includes("post-body"), "article still renders without a recorded thread");
assert.ok(!list.innerHTML.includes("billion-context/discussions"), "no discussion link when the manifest recorded none");
});

test("unknown slug degrades to a back link without a crash", async () => {
Expand Down
Loading