feat(glossy): add case-insensitive sorting

This commit is contained in:
swaits committed 2024-12-04 22:53:32 +01:00
1 parent 7f9a6856ba
commit f2052745e0
3 files changed
+17 -7

No files matched your search

+14 -5
View File
@@ -390,7 +390,8 @@
#let glossary(
title: "Glossary",
theme: theme-twocol,
groups: ()
ignore-case: false,
groups: (),
) = context {
// Collect and organize entries by group
let output = (:)
@@ -437,10 +438,18 @@
// Add non-empty groups to output
if current_entries.len() > 0 {
group = if group == none { "" } else { group }
output.insert(
group,
current_entries.sorted(key: e => e.short)
)
// sort entries by case insensitivity if requested
let sorted_entries = current_entries
// 1. create array of tuples with (lower [if ignore-case], entry)
.map(e => { if ignore-case { (lower(e.short), e) } else { (e.short, e) } })
// 2. sort the tuples (by first element then second)
.sorted(key: t => t.first())
// 3. strip away the tuple's first element, leaving an array of entries
.map(t => t.last())
// add entries to this group's output map
output.insert(group, sorted_entries)
}
}