```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)
);
const excalidrawBasePaths = new Set();
for (const path of remainingFiles) {
if (path.endsWith('.excalidraw.md')) {
excalidrawBasePaths.add(path.replace(/\.excalidraw\.md$/, ''));
remainingFiles.delete(path);
}
}
for (const path of remainingFiles) {
if (!path.endsWith('.md')) {
const basePath = path.replace(/\.excalidraw\.[^\.]+$/, '');
if (!excalidrawBasePaths.has(basePath)) {
remainingFiles.delete(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);
for (const path of remainingFiles) {
if (path.endsWith('.md') || path.startsWith('Meta/Excalidraw/')) {
remainingFiles.delete(path);
}
}
const orphanedExcalidraw = [...remainingFiles]
.map(path => path.replace(/\.excalidraw\.[^\.]+$/, '.excalidraw.md'))
.sort();
if (orphanedExcalidraw.length > 0) {
dv.list(orphanedExcalidraw.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 -""');
}
```