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:
1 parent
68945132fb
commit
03e8e62c70
10 files changed
+21
-21
No files matched your search
+2
-2
@@ -304,7 +304,7 @@ Customize glossary appearance by defining a theme with three functions:
|
|||||||
columns: (auto, 1fr, auto),
|
columns: (auto, 1fr, auto),
|
||||||
output,
|
output,
|
||||||
repeat([#h(0.25em) . #h(0.25em)]),
|
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`)
|
- `long`: Long form (can be `none`)
|
||||||
- `description`: Term description (can be `none`)
|
- `description`: Term description (can be `none`)
|
||||||
- `label`: Term's dictionary label
|
- `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
|
**NOTE:** If the theme does not emit `entry.label`, linking form terms to their
|
||||||
glossary entry will not work.
|
glossary entry will not work.
|
||||||
|
|||||||
@@ -406,20 +406,21 @@
|
|||||||
|
|
||||||
// Creates page number links back to each usage of a glossary term.
|
// Creates page number links back to each usage of a glossary term.
|
||||||
//
|
//
|
||||||
// This function generates a comma-separated list of page numbers, where each
|
// This function generates an array of page numbers, where each number links
|
||||||
// number links back to a usage of the term in the document. Duplicate page
|
// back to a usage of the term in the document. Duplicate page numers are
|
||||||
// numbers are removed to avoid redundancy.
|
// removed to avoid redundancy.
|
||||||
//
|
//
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// key (string): The glossary entry key
|
// key (string): The glossary entry key
|
||||||
//
|
//
|
||||||
// Returns:
|
// 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) = {
|
#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)
|
.map(meta => { // extract location and page number (or symbol)
|
||||||
let loc = meta.location()
|
let loc = meta.location()
|
||||||
let page = numbering(__default(loc.page-numbering(), "1"), ..counter(page).at(loc))
|
let page = numbering(__default(loc.page-numbering(), "1"), ..counter(page).at(loc))
|
||||||
@@ -427,7 +428,6 @@
|
|||||||
})
|
})
|
||||||
.dedup(key: ((loc, page)) => page) // deduplicate by page
|
.dedup(key: ((loc, page)) => page) // deduplicate by page
|
||||||
.map(((loc, page)) => link(loc, page)) // create links
|
.map(((loc, page)) => link(loc, page)) // create links
|
||||||
.join(", ")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formats a term string based on the specified mode.
|
// Formats a term string based on the specified mode.
|
||||||
@@ -575,7 +575,7 @@
|
|||||||
// - long: Long form of term (optional)
|
// - long: Long form of term (optional)
|
||||||
// - description: Term description (optional)
|
// - description: Term description (optional)
|
||||||
// - label: Term's dictionary label
|
// - 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
|
// - index: Zero-based entry index within group
|
||||||
// - total: Total entries in group
|
// - total: Total entries in group
|
||||||
// groups (array): Optional list of groups to include
|
// groups (array): Optional list of groups to include
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
columns: (1fr, auto),
|
columns: (1fr, auto),
|
||||||
gutter: 0.75em,
|
gutter: 0.75em,
|
||||||
[#short-display#long-display#description#entry.label],
|
[#short-display#long-display#description#entry.label],
|
||||||
text(fill: rgb("#666666"), entry.pages)
|
text(fill: rgb("#666666"), entry.pages.join(", "))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
// - long: Long form of term (optional)
|
// - long: Long form of term (optional)
|
||||||
// - description: Term description (optional)
|
// - description: Term description (optional)
|
||||||
// - label: Term's dictionary label
|
// - 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
|
// index: Zero-based entry index within group
|
||||||
// total: Total entries in group
|
// total: Total entries in group
|
||||||
entry: (entry, index, total) => {
|
entry: (entry, index, total) => {
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
left: 1em,
|
left: 1em,
|
||||||
bottom: 0.5em,
|
bottom: 0.5em,
|
||||||
block(
|
block(
|
||||||
[#term#entry.label#long-form#description #h(1em) (pp. #entry.pages)]
|
[#term#entry.label#long-form#description #h(1em) (pp. #entry.pages.join(", "))]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
columns: (1fr, auto),
|
columns: (1fr, auto),
|
||||||
gutter: 1em,
|
gutter: 1em,
|
||||||
[#short-display#entry.label#long-display#description#entry.label],
|
[#short-display#entry.label#long-display#description#entry.label],
|
||||||
[#entry.pages]
|
[#entry.pages.join(", ")]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
// - long: Long form of term (optional)
|
// - long: Long form of term (optional)
|
||||||
// - description: Term description (optional)
|
// - description: Term description (optional)
|
||||||
// - label: Term's dictionary label
|
// - 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
|
// index: Zero-based entry index within group
|
||||||
// total: Total entries in group
|
// total: Total entries in group
|
||||||
entry: (entry, index, total) => {
|
entry: (entry, index, total) => {
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
text(
|
text(
|
||||||
size: 0.6em,
|
size: 0.6em,
|
||||||
fill: gray.darken(20%),
|
fill: gray.darken(20%),
|
||||||
entry.pages
|
entry.pages.join(", ")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -27,6 +27,6 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
entry: (entry, index, total) => {
|
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(", "))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
// - long: Long form of term (optional)
|
// - long: Long form of term (optional)
|
||||||
// - description: Term description (optional)
|
// - description: Term description (optional)
|
||||||
// - label: Term's dictionary label
|
// - 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
|
// index: Zero-based entry index within group
|
||||||
// total: Total entries in group
|
// total: Total entries in group
|
||||||
entry: (entry, index, total) => {
|
entry: (entry, index, total) => {
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
[#short-display#entry.label#long-display#description], // Term with label
|
[#short-display#entry.label#long-display#description], // Term with label
|
||||||
[#repeat(h(0.25em) + "." + h(0.25em))], // Dotted leader line
|
[#repeat(h(0.25em) + "." + h(0.25em))], // Dotted leader line
|
||||||
[ . ], // A 1em wide dot so we definitely get some break between term and pages
|
[ . ], // A 1em wide dot so we definitely get some break between term and pages
|
||||||
[#entry.pages] // Page references
|
[#entry.pages.join(", ")] // Page references
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ which one to display.
|
|||||||
columns: (auto, 1fr, auto),
|
columns: (auto, 1fr, auto),
|
||||||
output,
|
output,
|
||||||
repeat([#h(0.25em) . #h(0.25em)]),
|
repeat([#h(0.25em) . #h(0.25em)]),
|
||||||
entry.pages,
|
entry.pages.join(", "),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ which one to display.
|
|||||||
columns: (auto, 1fr, auto),
|
columns: (auto, 1fr, auto),
|
||||||
output,
|
output,
|
||||||
repeat([#h(0.25em) . #h(0.25em)]),
|
repeat([#h(0.25em) . #h(0.25em)]),
|
||||||
entry.pages,
|
entry.pages.join(", "),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user