feat(glossy): add sort: true parameter to glossary()
This commit is contained in:
1 parent
c008b5bd86
commit
df889d8d72
5 files changed
+51
-9
No files matched your search
+3
-2
@@ -186,8 +186,9 @@ Display the glossary using the `glossary()` function:
|
|||||||
|
|
||||||
```typst
|
```typst
|
||||||
#glossary(
|
#glossary(
|
||||||
title: "Web Development Glossary", // Optional: defaults to Glossary
|
title: "Web Development Glossary", // Optional: defaults to Glossary theme:
|
||||||
theme: my-theme, // Optionaal: defaults to theme-twocol
|
my-theme, // Optional: defaults to theme-academic
|
||||||
|
sort: true, // Optional: whether or not to sort the glossary
|
||||||
ignore-case: false, // Optional: ignore case when sorting terms
|
ignore-case: false, // Optional: ignore case when sorting terms
|
||||||
groups: ("Web") // Optional: Filter to specific groups
|
groups: ("Web") // Optional: Filter to specific groups
|
||||||
)
|
)
|
||||||
|
|||||||
+12
-7
@@ -541,6 +541,7 @@
|
|||||||
#let glossary(
|
#let glossary(
|
||||||
title: "Glossary",
|
title: "Glossary",
|
||||||
theme: theme-academic,
|
theme: theme-academic,
|
||||||
|
sort: true,
|
||||||
ignore-case: false,
|
ignore-case: false,
|
||||||
groups: (),
|
groups: (),
|
||||||
) = context {
|
) = context {
|
||||||
@@ -601,13 +602,17 @@
|
|||||||
group = if group == none { "" } else { group }
|
group = if group == none { "" } else { group }
|
||||||
|
|
||||||
// sort entries by case insensitivity if requested
|
// sort entries by case insensitivity if requested
|
||||||
let sorted_entries = current_entries
|
let sorted_entries = if sort {
|
||||||
// 1. create array of tuples with (lower [if ignore-case], entry)
|
current_entries
|
||||||
.map(e => { if ignore-case { (lower(e.short), e) } else { (e.short, e) } })
|
// 1. create array of tuples with (lower [if ignore-case], entry)
|
||||||
// 2. sort the tuples (by first element then second)
|
.map(e => { if ignore-case { (lower(e.short), e) } else { (e.short, e) } })
|
||||||
.sorted() // NOTE: sorted() is NOT language-aware
|
// 2. sort the tuples (by first element then second)
|
||||||
// 3. strip away the tuple's first element, leaving an array of entries
|
.sorted() // NOTE: sorted() is NOT language-aware
|
||||||
.map(t => t.last())
|
// 3. strip away the tuple's first element, leaving an array of entries
|
||||||
|
.map(t => t.last())
|
||||||
|
} else {
|
||||||
|
current_entries
|
||||||
|
}
|
||||||
|
|
||||||
// add entries to this group's output map
|
// add entries to this group's output map
|
||||||
output.insert(group, sorted_entries)
|
output.insert(group, sorted_entries)
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
first:
|
||||||
|
short: "DAL"
|
||||||
|
long: "first"
|
||||||
|
|
||||||
|
second:
|
||||||
|
short: "cab"
|
||||||
|
long: "second"
|
||||||
|
|
||||||
|
third:
|
||||||
|
short: "delta"
|
||||||
|
long: "third"
|
||||||
|
|
||||||
|
fourth:
|
||||||
|
short: "COO"
|
||||||
|
long: "fourth"
|
||||||
|
|
||||||
|
fifth:
|
||||||
|
short: "cuckoo"
|
||||||
|
long: "fifth"
|
||||||
|
|
||||||
|
sixth:
|
||||||
|
short: "ČR"
|
||||||
|
long: "sixth"
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 183 KiB |
@@ -0,0 +1,13 @@
|
|||||||
|
#import "/lib.typ":*
|
||||||
|
|
||||||
|
#show: init-glossary.with(yaml("glossary.yml"))
|
||||||
|
|
||||||
|
@first, @second, @third, @fourth, @fifth, @sixth
|
||||||
|
|
||||||
|
#glossary(ignore-case: false, sort: true)
|
||||||
|
#line(length: 20em)
|
||||||
|
#glossary(ignore-case: true, sort: true)
|
||||||
|
#line(length: 20em)
|
||||||
|
#glossary(ignore-case: false, sort: false)
|
||||||
|
#line(length: 20em)
|
||||||
|
#glossary(ignore-case: true, sort: false)
|
||||||
Reference in new issue
Block a user