```dataviewjs const homePage = dv.pages().where(p => p.uid === "home").first(); if (!homePage) { throw new Error("No home page found (with uid: home)"); } const remainingFiles = new Set( app.vault.getFiles() .map(f => f.path) ); function removeLinkedFiles(page) { if (!page || !remainingFiles.has(page.file.path)) return; remainingFiles.delete(page.file.path); const metadataLinks = app.metadataCache.resolvedLinks[page.file.path] || {}; for (const linkedPath in metadataLinks) { if (!linkedPath.endsWith('.md')) { remainingFiles.delete(linkedPath); } } const additionalLinks = [ ...(page.file.outlinks || []), ...(page.file.inlinks || []), ...(page.file.embeddings || []) ]; for (const link of additionalLinks) { const linkedPage = dv.page(link); if (linkedPage) { removeLinkedFiles(linkedPage); } } } removeLinkedFiles(homePage); const orphanedAttachments = [...remainingFiles] .filter(path => !path.endsWith('.md')) .sort(); if (orphanedAttachments.length > 0) { dv.list(orphanedAttachments.map(path => { const vaultName = app.vault.getName(); const encodedPath = encodeURIComponent(path); return `${dv.fileLink(path)} — [Delete](obsidian://advanced-uri?vault=${encodeURIComponent(vaultName)}&filepath=${encodedPath}&commandid=app:delete-file)`; })); } else { dv.execute('LIST FROM -""'); } ```