Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

fix: unify graph frontmatter parsing

nash_sud12b83045348
diff --git a/src/lib/__tests__/wiki-graph.test.ts b/src/lib/__tests__/wiki-graph.test.ts
index 74dec7a1..d832586f 100644
--- a/src/lib/__tests__/wiki-graph.test.ts
+++ b/src/lib/__tests__/wiki-graph.test.ts
@@ -54,4 +54,30 @@ describe("buildWikiGraph frontmatter extraction", () => {
expect(graph.nodes).toHaveLength(1)
expect(graph.nodes[0].type).toBe("other")
})
+
+ it("parses CRLF frontmatter consistently with the rest of the application", async () => {
+ const buildWikiGraph = await loadBuildWikiGraph()
+ mockListDirectory.mockResolvedValue([mdFile("page.md")])
+ mockReadFile.mockResolvedValue(
+ "---\r\ntitle: CRLF Page\r\ntype: entity\r\n---\r\n# Fallback Heading\r\n",
+ )
+
+ const graph = await buildWikiGraph("/project")
+
+ expect(graph.nodes).toHaveLength(1)
+ expect(graph.nodes[0]).toMatchObject({ label: "CRLF Page", type: "entity" })
+ })
+
+ it("uses YAML parsing for quoted values that contain a colon", async () => {
+ const buildWikiGraph = await loadBuildWikiGraph()
+ mockListDirectory.mockResolvedValue([mdFile("page.md")])
+ mockReadFile.mockResolvedValue(
+ '---\ntitle: "Attention: Architecture"\ntype: "Concept"\n---\n# Fallback Heading\n',
+ )
+
+ const graph = await buildWikiGraph("/project")
+
+ expect(graph.nodes).toHaveLength(1)
+ expect(graph.nodes[0]).toMatchObject({ label: "Attention: Architecture", type: "concept" })
+ })
})
diff --git a/src/lib/wiki-graph.ts b/src/lib/wiki-graph.ts
index a73e7d12..4fd1eb7e 100644
--- a/src/lib/wiki-graph.ts
+++ b/src/lib/wiki-graph.ts
@@ -2,6 +2,7 @@ import { readFile, listDirectory } from "@/commands/fs"
import type { FileNode } from "@/types/wiki"
import { buildRetrievalGraph, calculateRelevance } from "./graph-relevance"
import { normalizePath } from "@/lib/path-utils"
+import { parseFrontmatter } from "@/lib/frontmatter"
import Graph from "graphology"
import louvain from "graphology-communities-louvain"
@@ -126,15 +127,9 @@ function flattenMdFiles(nodes: FileNode[]): FileNode[] {
return files
}
-function extractFrontmatterBlock(content: string): string {
- const fmMatch = content.match(/^---\n([\s\S]*?)\n---/)
- return fmMatch ? fmMatch[1] : ""
-}
-
function extractTitle(content: string, fileName: string): string {
- const frontmatter = extractFrontmatterBlock(content)
- const frontmatterTitleMatch = frontmatter.match(/^title:\s*["']?(.+?)["']?\s*$/m)
- if (frontmatterTitleMatch) return frontmatterTitleMatch[1].trim()
+ const title = parseFrontmatter(content).frontmatter?.title
+ if (typeof title === "string" && title.trim()) return title.trim()
const headingMatch = content.match(/^#\s+(.+)$/m)
if (headingMatch) return headingMatch[1].trim()
@@ -143,9 +138,8 @@ function extractTitle(content: string, fileName: string): string {
}
function extractType(content: string): string {
- const frontmatter = extractFrontmatterBlock(content)
- const frontmatterTypeMatch = frontmatter.match(/^type:\s*["']?(.+?)["']?\s*$/m)
- if (frontmatterTypeMatch) return frontmatterTypeMatch[1].trim().toLowerCase()
+ const type = parseFrontmatter(content).frontmatter?.type
+ if (typeof type === "string" && type.trim()) return type.trim().toLowerCase()
return "other"
}