diff --git a/src/components/EditionToc.astro b/src/components/EditionToc.astro index f10e9b6..975f4e3 100644 --- a/src/components/EditionToc.astro +++ b/src/components/EditionToc.astro @@ -8,11 +8,20 @@ const { label = "Table des matières" } = Astro.props; -const entries = (await getCollection(collection)) - .sort((a, b) => (a.data.order ?? 0) - (b.data.order ?? 0)); +const slugOf = (entry) => String(entry.id).replace(/\.(md|mdx)$/i, ""); +const hrefOf = (entry) => `${basePath}/${slugOf(entry)}/`; -const routeSlug = (entry) => String(entry.id || "").replace(/\.(md|mdx)$/i, ""); -const href = (entry) => `${basePath}/${routeSlug(entry)}/`; +const collator = new Intl.Collator("fr", { sensitivity: "base", numeric: true }); + +const entries = [...await getCollection(collection)].sort((a, b) => { + const ao = Number(a.data.order ?? 9999); + const bo = Number(b.data.order ?? 9999); + if (ao !== bo) return ao - bo; + + const at = String(a.data.title ?? a.data.term ?? slugOf(a)); + const bt = String(b.data.title ?? b.data.term ?? slugOf(b)); + return collator.compare(at, bt); +}); ---