feat(glossy): add case-insensitive sorting
This commit is contained in:
3 files changed
+17
-7
No files matched your search
@@ -154,8 +154,9 @@ Display the glossary using the `glossary()` function:
|
|||||||
|
|
||||||
```typst
|
```typst
|
||||||
#glossary(
|
#glossary(
|
||||||
title: "Web Development Glossary",
|
title: "Web Development Glossary", // Optional: defaults to Glossary
|
||||||
theme: my-theme,
|
theme: my-theme, // Optionaal: defaults to theme-twocol
|
||||||
|
ignore-case: false, // Optional: ignore case when sorting terms
|
||||||
groups: ("Web") // Optional: Filter to specific groups
|
groups: ("Web") // Optional: Filter to specific groups
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|||||||
Binary file not shown.
@@ -390,7 +390,8 @@
|
|||||||
#let glossary(
|
#let glossary(
|
||||||
title: "Glossary",
|
title: "Glossary",
|
||||||
theme: theme-twocol,
|
theme: theme-twocol,
|
||||||
groups: ()
|
ignore-case: false,
|
||||||
|
groups: (),
|
||||||
) = context {
|
) = context {
|
||||||
// Collect and organize entries by group
|
// Collect and organize entries by group
|
||||||
let output = (:)
|
let output = (:)
|
||||||
@@ -437,10 +438,18 @@
|
|||||||
// Add non-empty groups to output
|
// Add non-empty groups to output
|
||||||
if current_entries.len() > 0 {
|
if current_entries.len() > 0 {
|
||||||
group = if group == none { "" } else { group }
|
group = if group == none { "" } else { group }
|
||||||
output.insert(
|
|
||||||
group,
|
// sort entries by case insensitivity if requested
|
||||||
current_entries.sorted(key: e => e.short)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user