Skip to content

fix: extract frontmatter title when cleaning up deleted wiki pages#517

Open
yudaiyan wants to merge 2 commits into
nashsu:mainfrom
yudaiyan:fix/source-delete-title
Open

fix: extract frontmatter title when cleaning up deleted wiki pages#517
yudaiyan wants to merge 2 commits into
nashsu:mainfrom
yudaiyan:fix/source-delete-title

Conversation

@yudaiyan

@yudaiyan yudaiyan commented Jul 1, 2026

Copy link
Copy Markdown

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.

yudaiyan added 2 commits July 1, 2026 17:19
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 chuenchen309 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants