You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 year = date[0];
let folderPath = page.file.folder.split('/');
if (!grouped[year]) {
grouped[year] = {};
}
addToHierarchy(folderPath, grouped[year]);
}
let sortedYears = Object.keys(grouped).sort().reverse();
for (let year of sortedYears) {
dv.header(2, `π― ${year}`);
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[year]), {cls: 'dataview-table'});
}