- [[Published Orphans]]
- [[Attachment Orphans]]
```dataviewjs
const homePage = dv.pages().where(p => p.uid === "home").first();
if (!homePage) {
throw new Error("No home page found (with uid: home)");
}
const allPageRecords = dv.array(dv.pages());
const allPages = new Set(allPageRecords.map(p => p.file.path));
function normalizeTags(page) {
const rawTags = page?.file?.tags || [];
return [...new Set(rawTags.map(tag => tag.toLowerCase()))];
}
const tagToPages = new Map();
for (const page of allPageRecords) {
for (const tag of normalizeTags(page)) {
if (!tagToPages.has(tag)) {
tagToPages.set(tag, new Set());
}
tagToPages.get(tag).add(page);
}
}
function removeLinkedPages(startPage) {
if (!startPage || !allPages.has(startPage.file.path)) return;
allPages.delete(startPage.file.path);
const allLinks = [
...(startPage.file.outlinks || []),
...(startPage.file.inlinks || []),
...(startPage.file.embeddings || [])
];
for (const link of allLinks) {
const linkedPage = dv.page(link);
if (linkedPage) {
removeLinkedPages(linkedPage);
}
}
for (const tag of normalizeTags(startPage)) {
const taggedPages = tagToPages.get(tag);
if (!taggedPages) continue;
for (const taggedPage of taggedPages) {
removeLinkedPages(taggedPage);
}
}
}
removeLinkedPages(homePage);
if (allPages.size > 0) {
dv.list([...allPages].sort().map(path => dv.fileLink(path)));
} else {
dv.execute('LIST FROM -""');
}
```