Identify pages with specific tags that are missing from an MOC

Hi,

I’m in the process of revamping the way I organise my vault and wanted to share a method I’ve developed for enhancing my MOC pages.

I’ve started incorporating a Dataview JavaScript query into my MOC pages based on the example in this post. This approach helps me identify pages with specific tags that are missing from my hand-curated sections.

Let me know if you have an ideas for cleaning it up or improving it - I’m very much a newbie when it comes to both DV and JS.


let currentPage = dv.current().file.path;
let linkedPages = new Set();
let stack = [currentPage];

while (stack.length > 0) {
    let elem = stack.pop();
    let meta = dv.page(elem);
    if (!meta) continue; // ignore links to pages that don't exist yet

    for (let link of meta.file.inlinks.concat(meta.file.outlinks).array()) {
        if (linkedPages.has(link.path)) continue; // only look at pages we haven't seen yet
        linkedPages.add(link.path);
        stack.push(link.path);
    }
}

// Fetch all pages with either the "fitness" or "health" tag
let taggedPages = dv.pages("#fitness or #health")
    .where(p => !linkedPages.has(p.file.path)) // Exclude pages that are in the set of linked pages
    .map(p => [p.file.link, p.file.name]); // Map the pages to the desired format for the table

// Display the table
dv.table(["File Link", "File Name"], taggedPages);