DVJS - Missing notes with incoming link count

Setup

This is a DataviewJS query to find files that do not exist and count how often you link to each of these files.

Code

Don't forget to start and end the code block with three backticks.

dataviewjs
dv.paragraph("## Uncreated Notes with Mentions Count");

let links = dv.app.metadataCache.unresolvedLinks;
let data = [];

for (let file in links) {
    for (let unresolved in links[file]) {
        data.push({ 
            note: unresolved, 
            mentions: links[file][unresolved] 
        });
    }
}

let groupedData = data.reduce((acc, curr) => {
    let found = acc.find(item => item.note === curr.note);
    if (found) {
        found.mentions += curr.mentions;
    } else {
        acc.push(curr);
    }
    return acc;
}, []);

groupedData.sort((a, b) => b.mentions - a.mentions);

dv.table(["Uncreated Note", "Mentions"], groupedData.map(item => [item.note, item.mentions]));

Effect

DVJS - missing notes with incoming link count-20240603092945119.png