import { Node } from 'prosemirror-model'; /** * The distinct target slugs of every `[[wikilink]]` and every `![[embed]]` * (transclusion, issue #135) in a document (issue #47). Used server-side to * maintain the `page_links` index on every content change, so backlinks and * phantom (missing-target) links can be queried — an embed is semantically a * reference, so it registers as a link too. Order of first appearance is * preserved; duplicates are collapsed. */ export function extractWikilinkSlugs(doc: Node): string[] { const slugs: string[] = []; const seen = new Set(); doc.descendants((node) => { if (node.type.name === 'wikilink' || node.type.name === 'transclusion') { const slug = node.attrs.targetSlug as string; if (slug && !seen.has(slug)) { seen.add(slug); slugs.push(slug); } } }); return slugs; }