title |
cssclasses |
Dangling Links |
dangle-dashboard |
row-lines |
|
const result = {};
function process(referingFile, unresolvedLinks) {
for (const link of Object.keys(unresolvedLinks)) {
const processedLink = dv.fileLink(link);
if (!result[processedLink]) {
result[processedLink] = [dv.fileLink(referingFile)];
} else {
result[processedLink].push(dv.fileLink(referingFile));
}
}
}
for (const [referingFile, unresolvedLink] of Object.entries(dv.app.metadataCache.unresolvedLinks)) {
if (!referingFile.startsWith("999 Template") && !referingFile.startsWith("300 Resources/Obsidian Style Guide")) {
process(referingFile, unresolvedLink);
}
}
const rows = Object.entries(result)
.map(([unresolvedLink, referingFiles]) => [unresolvedLink, referingFiles]);
rows.sort((a, b) => {
if (a[0] < b[0]) {
return -1;
} else if (a[0] > b[0]) {
return 1;
} else {
return 0;
}
});
function quickSort(arr) {
if (arr.length <= 1) {
return arr;
}
const pivotIndex = Math.floor(arr.length / 2);
const pivot = arr[pivotIndex];
const left = [];
const right = [];
for (let i = 0; i < arr.length; i++) {
if (i === pivotIndex) {
continue;
}
const current = arr[i];
if (current[0] < pivot[0]) {
left.push(current);
} else {
right.push(current);
}
}
return [...quickSort(left), pivot, ...quickSort(right)];
}
const sortedRows = quickSort(rows);
dv.table(["Unresolved Link", "Contained in"], sortedRows);