38 lines
1.0 KiB
Markdown
38 lines
1.0 KiB
Markdown
# By Context
|
|
|
|
All assigned entities (`parent` set), grouped by their **root context** — the topmost ancestor reached by walking the `parent` chain.
|
|
|
|
```dataviewjs
|
|
const ALL = dv.pages('""').where(p =>
|
|
p.parent && !p.file.path.startsWith("_templates/")
|
|
);
|
|
|
|
function rootContext(page, depth = 0) {
|
|
if (depth > 16) return "(cycle)";
|
|
if (!page.parent) return page.file.name;
|
|
const link = page.parent;
|
|
const path = (link && link.path) || (typeof link === "string" ? link : null);
|
|
if (!path) return "(unresolved)";
|
|
const parent = dv.page(path);
|
|
if (!parent) return path;
|
|
if (!parent.parent) return parent.file.name;
|
|
return rootContext(parent, depth + 1);
|
|
}
|
|
|
|
const groups = {};
|
|
for (const p of ALL) {
|
|
const ctx = rootContext(p);
|
|
(groups[ctx] = groups[ctx] || []).push(p);
|
|
}
|
|
|
|
for (const ctx of Object.keys(groups).sort()) {
|
|
dv.header(2, ctx);
|
|
dv.table(
|
|
["Entity", "Direct parent", "Status"],
|
|
groups[ctx]
|
|
.sort((a, b) => (a.file.name > b.file.name ? 1 : -1))
|
|
.map(p => [p.file.link, p.parent, p.status ?? ""])
|
|
);
|
|
}
|
|
```
|