let pages = [...dv.pages().where(p => p.file.path.includes('/'))];
pages.sort((a, b) => b.file.name.localeCompare(a.file.name));
let grouped = {};
function addToHierarchy(pathArray, obj) {
let part = pathArray[0];
if (!obj[part]) {
obj[part] = { count: 0, children: {} };
}
obj[part].count++;
if (pathArray.length > 1) {
addToHierarchy(pathArray.slice(1), obj[part].children);
}
}
for (let page of pages) {
let date = page.file.name.split('-');
if (date.length < 2) continue;
let yearMonth = `${date[0]}-${date[1]}`;
let folderPath = page.file.folder.split('/');
if (!grouped[yearMonth]) {
grouped[yearMonth] = {};
}
addToHierarchy(folderPath, grouped[yearMonth]);
}
let sortedMonths = Object.keys(grouped).sort().reverse();
for (let yearMonth of sortedMonths) {
dv.header(2, `π― ${yearMonth}`);
function displayHierarchy(obj) {
let html = '<ul>';
let keys = Object.keys(obj).sort();
for (let key of keys) {
html += `<li>π ${key} (${obj[key].count})`;
html += displayHierarchy(obj[key].children);
html += `</li>`;
}
html += '</ul>';
return html;
}
dv.el('div', displayHierarchy(grouped[yearMonth]), {cls: 'dataview-table'});
}
Last active
February 24, 2025 17:15
-
-
Save marcelometal/d638b7eb8885c4c49424283da581aecc to your computer and use it in GitHub Desktop.
Obisidian + DataView: Analytics Month
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment