feat(mira): 7B.3g wiki UI 樹狀渲染 + 跨 wiki 連結
對應 polaris/mira/.agents/specs/mira-app/design.md §5.2 + §3.5.12。 `/mira/wiki/[pageName]`: - 抓 wiki-page 後平行撈所有 wiki-paragraph / triplet / wiki-page,client-side 用 parent_id filter (KBDB 沒 parent_id server filter,且 tag filter 還有 KI-3 bug) - 按 facet 分區渲染:facet 標題 + paragraph markdown + 該段的 triplets - facet 預設展開(看一篇要看內容)/ triplets 預設折疊(leo Logseq outliner 習慣) - **triplet A/B 拆字串 「A >> 關係 >> B」**,若 A 或 B 對得上既有 wiki entity → render 成 <Link> 跨 wiki 跳轉,是 Wikipedia-like 體驗的關鍵 - fallback:非 wiki-page block(schema/index/log 等)直接 render content `/mira/wiki`:列表用 wiki-page 的 content (= entity 名稱) 當標題,不是 page_name slug。 mira.css 加 `.mira-wiki-detail` 不破版 + h2 底線,避免長 cypher 字串撐爆右邊界。 TS check pass。
This commit is contained in:
@@ -41,15 +41,27 @@ export default function WikiIndexPage() {
|
||||
const me = (await meRes.json()) as { api_key: string };
|
||||
const headers = { Authorization: `Bearer ${me.api_key}` };
|
||||
|
||||
// 用 tag=mira-wiki 一次撈所有相關 blocks(KBDB list endpoint 2026-05-07 加了 tag filter)
|
||||
// 撈所有 type=wiki-page,再 client 端過濾 tags 含 'mira-wiki'
|
||||
// 原本 ?tag=mira-wiki 撞 KBDB worker D1 bug(malformed JSON),改 type filter
|
||||
// 待 KBDB 修 tag filter 後可改回(SDD 待開 kbdb-tag-filter-fix)
|
||||
const res = await fetch(
|
||||
`${KBDB_BASE}/blocks?tag=mira-wiki&limit=200`,
|
||||
`${KBDB_BASE}/blocks?type=wiki-page&limit=200`,
|
||||
{ headers },
|
||||
);
|
||||
if (!res.ok) throw new Error(`KBDB ${res.status}`);
|
||||
const data = await res.json();
|
||||
if (cancelled) return;
|
||||
const blocks: Block[] = data.blocks ?? [];
|
||||
const allWikiBlocks: Block[] = data.blocks ?? [];
|
||||
// Client 端過濾:只留 tags 含 'mira-wiki'
|
||||
const blocks: Block[] = allWikiBlocks.filter((b) => {
|
||||
if (!b.tags_json) return false;
|
||||
try {
|
||||
const tags = JSON.parse(b.tags_json) as string[];
|
||||
return tags.includes('mira-wiki');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
const tagsOf = (b: Block): string[] => {
|
||||
if (!b.tags_json) return [];
|
||||
@@ -175,8 +187,12 @@ export default function WikiIndexPage() {
|
||||
<WikiCardLink
|
||||
key={p.id}
|
||||
page_name={p.page_name}
|
||||
title={p.page_name}
|
||||
excerpt={firstLineOf(p.content)}
|
||||
title={(p.content || '').trim() || p.page_name}
|
||||
excerpt={
|
||||
p.created_at
|
||||
? `建立 ${new Date(p.created_at * 1000).toLocaleString('zh-TW')}`
|
||||
: p.page_name
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user