diff --git a/src/web/client.ts b/src/web/client.ts index a26bc182f0..bb4e50bb00 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -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; @@ -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 + '
' + escapeHtml(item.date || "\u2014") + '' + escapeHtml(kindLabel) + '' + escapeHtml(t("bl.back")) + "
" + const dUrl = blogDiscussionUrl(item); + const commentLink = dUrl ? '' + escapeHtml(t("bl.comment")) + "" : ""; + // 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 = 'EN \u4e2d\u6587'; + host.innerHTML = offlineNote + '
' + escapeHtml(item.date || "\u2014") + '' + escapeHtml(kindLabel) + '' + escapeHtml(t("bl.back")) + " " + langToggle + " " + commentLink + "
" + '

' + escapeHtml(title) + "

" + '
' + html + "
"; return; diff --git a/src/web/i18n.ts b/src/web/i18n.ts index ff7f1e5a8a..7fcaa2b120 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -38,6 +38,7 @@ export const MESSAGES: Record> = { "bl.kind_article": "长文", "bl.empty": "这个版本还没内置文章。", "bl.back": "← 全部文章", + "bl.comment": "去 GitHub 评论", "bl.nf": "文章不存在或已被移除。", "bl.offline": "上次拉取未完成,显示的是缓存内容(上次成功拉取或包内文章)。", "nav.connect": "接入", @@ -762,6 +763,7 @@ export const MESSAGES: Record> = { "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", diff --git a/tests/web-blog-route.test.ts b/tests/web-blog-route.test.ts index 373ae4232c..242a9d392c 100644 --- a/tests/web-blog-route.test.ts +++ b/tests/web-blog-route.test.ts @@ -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: "

hi

", htmlZh: "

你好

" }] }; +const FEED = { items: [{ id: "demo", kind: "post", date: "2026-10-08", title: "Demo post", titleZh: "演示", excerpt: "ex", html: "

hi

", htmlZh: "

你好

", 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 @@ -113,6 +113,19 @@ test("#/blog/ 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("

hi

") || list.innerHTML.includes("\u4f60\u597d

")), "article body rendered (locale-twin aware)"); assert.ok(list.innerHTML.includes(''), "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"), "Chinese toggle label rendered"); +}); + +test("#/blog/ 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

" }] }; + 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 () => {