Enchiridion sections

const here = dv.current().file.folder;
const notes = dv.pages(`"${here}/section"`).array();
 
const num = s => {
  const n = Number(s);
  return Number.isNaN(n) ? null : n;
};
 
notes.sort((a, b) => {
  const na = num(a.file.name), nb = num(b.file.name);
  if (na !== null && nb !== null) return na - nb;   // both numeric → numeric order
  if (na !== null) return -1;                        // numbers before names
  if (nb !== null) return 1;
  return a.file.name.localeCompare(b.file.name);     // both non-numeric → alphabetical
});
 
for (const p of notes) {
  dv.paragraph(`<details><summary>${p.file.name}</summary>\n\n![[${p.file.name}]]\n\n</details>`);
}
Link to original