TagNotes Count
course14
todo12
python3
script1
shell1
sea-ice1
sea-ice-dynamics1
project1
numpy1
lecture1

table length(rows) as "Notes Count"
from ""
flatten file.tags as tag
group by tag
sort length(rows) desc
let tagCounts = {};
 
// Loop through each file in the vault
for (let page of dv.pages()) {
    if (page.file.tags) {
        for (let tag of page.file.tags) {
            // Remove the leading '#' from the tag
            let cleanedTag = tag.replace(/^#/, '');
            // Increment the count for each tag
            if (tagCounts[cleanedTag]) {
                tagCounts[cleanedTag] += 1;
            } else {
                tagCounts[cleanedTag] = 1;
            }
        }
    }
}
 
// Convert the tags to a sorted array of [tag, count] pairs
let sortedTags = Object.entries(tagCounts)
    .sort((a, b) => b[1] - a[1]); // Sort by count in descending order
 
// Output the tags and their counts in a markdown table
let table = `| Tag | Notes Count |\n|-----|-------|\n`;
for (let [tag, count] of sortedTags) {
    table += `| ${tag} | ${count} |\n`;
}
dv.paragraph(table);