feat(glossy): Return array of pages in theme

Instead of returning an opaque context element with a fixed list of the
pages, return an array of context elements with each a page
(already unique!).
This is conceptually cleaner. Now it's the themes responsability to join
the array of unique pages however it wants. Most times, this will be a
`.join(", ")`, but could be e.g. `.first()` if the theme only wants to
show the page of the first occurance of this term.
Also update the documentation.

Breaking API change in the themes.
No visual differences (tests remain the same), but there are binary
differences.
This commit is contained in:
swaits authored and swaits committed 2025-10-26 16:00:21 -06:00
1 parent 68945132fb
commit 03e8e62c70
10 files changed
+21 -21

No files matched your search

+2 -2
View File
@@ -304,7 +304,7 @@ Customize glossary appearance by defining a theme with three functions:
columns: (auto, 1fr, auto),
output,
repeat([#h(0.25em) . #h(0.25em)]),
entry.pages,
entry.pages.join(", "),
)
)
}
@@ -317,7 +317,7 @@ Entry fields available to themes:
- `long`: Long form (can be `none`)
- `description`: Term description (can be `none`)
- `label`: Term's dictionary label
- `pages`: Linked page numbers where term appears
- `pages`: Array of linked page numbers where term appears
**NOTE:** If the theme does not emit `entry.label`, linking form terms to their
glossary entry will not work.
+8 -8
View File
@@ -406,20 +406,21 @@
// Creates page number links back to each usage of a glossary term.
//
// This function generates a comma-separated list of page numbers, where each
// number links back to a usage of the term in the document. Duplicate page
// numbers are removed to avoid redundancy.
// This function generates an array of page numbers, where each number links
// back to a usage of the term in the document. Duplicate page numers are
// removed to avoid redundancy.
//
// Parameters:
// key (string): The glossary entry key
//
// Returns:
// content: Comma-separated list of linked page numbers
// array: Linked page numbers
//
// Example output: "1, 3, 5" where each number links to the term usage on that page
// Example output after a typical .join(", "):
// "1, 3, 5" where each number links to the term usage on that page
//
#let __create_backlinks(key) = {
return context query(__term_label(key)) // find all reference
return query(__term_label(key)) // find all reference
.map(meta => { // extract location and page number (or symbol)
let loc = meta.location()
let page = numbering(__default(loc.page-numbering(), "1"), ..counter(page).at(loc))
@@ -427,7 +428,6 @@
})
.dedup(key: ((loc, page)) => page) // deduplicate by page
.map(((loc, page)) => link(loc, page)) // create links
.join(", ")
}
// Formats a term string based on the specified mode.
@@ -575,7 +575,7 @@
// - long: Long form of term (optional)
// - description: Term description (optional)
// - label: Term's dictionary label
// - pages: Linked page numbers where term appears
// - pages: Array of linked page numbers where term appears
// - index: Zero-based entry index within group
// - total: Total entries in group
// groups (array): Optional list of groups to include
+1 -1
View File
@@ -40,7 +40,7 @@
columns: (1fr, auto),
gutter: 0.75em,
[#short-display#long-display#description#entry.label],
text(fill: rgb("#666666"), entry.pages)
text(fill: rgb("#666666"), entry.pages.join(", "))
)
}
)
+2 -2
View File
@@ -36,7 +36,7 @@
// - long: Long form of term (optional)
// - description: Term description (optional)
// - label: Term's dictionary label
// - pages: Linked page numbers where term appears
// - pages: Array of linked page numbers where term appears
// index: Zero-based entry index within group
// total: Total entries in group
entry: (entry, index, total) => {
@@ -62,7 +62,7 @@
left: 1em,
bottom: 0.5em,
block(
[#term#entry.label#long-form#description #h(1em) (pp. #entry.pages)]
[#term#entry.label#long-form#description #h(1em) (pp. #entry.pages.join(", "))]
)
)
)
+1 -1
View File
@@ -38,7 +38,7 @@
columns: (1fr, auto),
gutter: 1em,
[#short-display#entry.label#long-display#description#entry.label],
[#entry.pages]
[#entry.pages.join(", ")]
)
}
)
+2 -2
View File
@@ -44,7 +44,7 @@
// - long: Long form of term (optional)
// - description: Term description (optional)
// - label: Term's dictionary label
// - pages: Linked page numbers where term appears
// - pages: Array of linked page numbers where term appears
// index: Zero-based entry index within group
// total: Total entries in group
entry: (entry, index, total) => {
@@ -83,7 +83,7 @@
text(
size: 0.6em,
fill: gray.darken(20%),
entry.pages
entry.pages.join(", ")
)
)
)
+1 -1
View File
@@ -27,6 +27,6 @@
},
entry: (entry, index, total) => {
(entry.short + entry.label, entry.long, entry.description, entry.pages)
(entry.short + entry.label, entry.long, entry.description, entry.pages.join(", "))
}
)
+2 -2
View File
@@ -36,7 +36,7 @@
// - long: Long form of term (optional)
// - description: Term description (optional)
// - label: Term's dictionary label
// - pages: Linked page numbers where term appears
// - pages: Array of linked page numbers where term appears
// index: Zero-based entry index within group
// total: Total entries in group
entry: (entry, index, total) => {
@@ -65,7 +65,7 @@
[#short-display#entry.label#long-display#description], // Term with label
[#repeat(h(0.25em) + "." + h(0.25em))], // Dotted leader line
[ . ], // A 1em wide dot so we definitely get some break between term and pages
[#entry.pages] // Page references
[#entry.pages.join(", ")] // Page references
)
)
},
+1 -1
View File
@@ -79,7 +79,7 @@ which one to display.
columns: (auto, 1fr, auto),
output,
repeat([#h(0.25em) . #h(0.25em)]),
entry.pages,
entry.pages.join(", "),
)
)
}
+1 -1
View File
@@ -117,7 +117,7 @@ which one to display.
columns: (auto, 1fr, auto),
output,
repeat([#h(0.25em) . #h(0.25em)]),
entry.pages,
entry.pages.join(", "),
)
)
}