fix: extract frontmatter title when cleaning up deleted wiki pages#517
fix: extract frontmatter title when cleaning up deleted wiki pages#517yudaiyan wants to merge 2 commits into
Conversation
Previously cleanupDeletedWikiPages always set title to empty string, which meant only file-stem slugs were used to match wikilinks in index.md and overview.md. Pages whose wikilinks used display titles (e.g. [[KV Cache]] for file kv-cache.md) were silently left behind. Now reads the frontmatter title from each wiki page before deletion, so both slug-form and title-form wikilinks are matched and cleaned.
chuenchen309
left a comment
There was a problem hiding this comment.
Nice catch on the title-form wikilink gap. I traced the call path to make sure the fix lands and think there may be a problem — would appreciate a sanity check in case I missed a path.
The only caller of cleanupDeletedWikiPages is cleanupDeletedFiles in project-file-sync.ts, and its input comes from file-watch tasks where kind === "deleted":
const deleted = tasks.filter((t) => ... t.kind === "deleted").map(...)
const wikiPages = deleted.filter(isWikiPageForCascade)
const wikiPagesToClean = wikiPages.filter((p) => !deletedWikiSlugs.has(getFileStem(p)))
await cleanupDeletedWikiPages(project.path, wikiPagesToClean)By the time this runs, those pages are already gone from disk (that's what a deleted watch event means), so readFile(${pp}/${path}) throws for essentially every page, the catch fires, and title stays "" — the same slug-only behavior as before. The // page already deleted comment is really the normal case in this path, not an edge case, so as written this looks like a no-op for the reported bug.
The pattern that does work is already in cascadeDeleteWikiPagesWithRefs, which captures { slug, title } before deleting the page. For the external-deletion path here the content is unrecoverable from disk, so the title would need to come from persisted metadata (e.g. the embedding index) rather than a post-hoc readFile.
One more if title recovery moves earlier: extractFrontmatterTitle matches /^title:/m anywhere in the document, not just inside the frontmatter block, so a body line like title: ... (in a code block or example) can be picked up as the page title — the same footgun #577 fixed for the other extractors. Worth reusing a frontmatter-framing parse there.
Minor: the new const deletedInfos block indentation looks off, and the .worktrees/ gitignore line seems unrelated to this change.
Previously cleanupDeletedWikiPages always set title to empty string, which meant only file-stem slugs were used to match wikilinks in index.md and overview.md. Pages whose wikilinks used display titles (e.g. [[KV Cache]] for file kv-cache.md) were silently left behind. Now reads the frontmatter title from each wiki page before deletion, so both slug-form and title-form wikilinks are matched.