What can I say, …well, I have become weak.
For fun, I asked the great AI oracle chatopenAI…
It spat out the code without flinching.
What that means for the future - not only here in the forum - I dare not imagine.
Well, for all those who might be looking for something similar, here is the solution:
```dataviewjs
let groupedThema = {}
dv.pages()
.where(p => p.MusType == "Vortrag" || p.MusType == "Lesung")
.forEach(page => {
if(!Array.isArray(page.thema)) {
page.thema = [page.thema];
}
for (let t of page.thema) {
if (!groupedThema[t]) {
groupedThema[t] = []
}
groupedThema[t].push({
file: page.file,
jahr: page.jahr,
alias: page.alias
});
}
});
let sortedThema = Object.keys(groupedThema).sort((a, b) => groupedThema[b].length - groupedThema[a].length)
for (let key of sortedThema) {
dv.header(3, key + " (" + groupedThema[key].length + ")");
dv.table(["Thema", "Jahr"],
groupedThema[key]
.sort((a, b) => b.jahr - a.jahr)
.map(p => ["[[" + p.file.path + "|" + p.alias + "]]", p.jahr]));
}