Show all metadata in the vault

Language:: JavaScript, Plugin - Dataview
Program:: Obsidian

Summary

Use DVJS to show all the metadata in the vault

Code

const pagelimit = 5;
const metadataMap = {};

dv.pages().forEach(page => {
    Object.keys(page).forEach(metadata => {
        if (metadata === 'file') return;
        metadata = metadata.toLowerCase().replaceAll(" ", "-")
        if (!metadataMap[metadata]) {
            metadataMap[metadata] = []
        }
        if (!metadataMap[metadata].some(l => l.path === page.file.link.path)) {
            metadataMap[metadata].push(page);
        }
    })
})

dv.table(["meta data", "page count", `pages (first ${pagelimit})`, "Values"], Object.keys(metadataMap).sort().map(key => (
[key, 
 metadataMap[key].length, 
 dv.array(metadataMap[key]).file.link.limit(pagelimit), 
 dv.array(metadataMap[key]).limit(pagelimit)[key]
 ])))

Explanation

Result


up:: ๐Ÿงช Code Diary