Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
meisZWFLZ committed Jul 11, 2024
2 parents eec330e + 454c788 commit 75c7a51
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
16 changes: 8 additions & 8 deletions entries.typ
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
witness: "",
body,
) = {
let (state, entry-label) = if section == "frontmatter" {
(globals.frontmatter-entries, label("notebook-frontmatter"))
let (state, entry-type) = if section == "frontmatter" {
(globals.frontmatter-entries, "notebook-frontmatter")
} else if section == "body" {
(globals.entries, label("notebook-body"))
(globals.entries, "notebook-body")
} else if section == "appendix" {
(globals.appendix-entries, label("notebook-appendix"))
(globals.appendix-entries, "notebook-appendix")
} else {
panic("No valid entry type selected")
}

state.update(
entries => {
// let unique-label = label(entry-type + ":" + str(entries.len()))
let entry-type-label = label(entry-type)
// Inject the proper labels and settings changes into the user's entry body
let final-body = if entries.len() == 0 {
[#counter(page).update(1)] // Correctly set the page number for each section
} + [
#metadata(none) #entry-label
let final-body = [
#metadata(none) #entry-type-label
#counter(footnote).update(0)
] + body // Place a label on blank content to the table of contents can find each entry

Expand Down
5 changes: 3 additions & 2 deletions internals.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "./globals.typ"
#import "./themes/themes.typ"
#import "/utils.typ"

#let fallback-to-default(key, theme) = {
let component = theme.at(key, default: none)
Expand Down Expand Up @@ -27,9 +28,9 @@
#let print-entries(theme: (:)) = {
let print-helper(section, state) = {
locate(loc => {
for entry in state.final(loc).sorted(key: entry=>entry.ctx.date) [
for (index, entry) in utils.sort_entries(state.final(loc)).enumerate() [
#let entry-func = fallback-to-default(section + "-entry", theme)
#let body = [] + entry.body
#let body = if index == 0 [#counter(page).update(1)] else [] + entry.body
#entry-func(body, ctx: entry.ctx)
]
})
Expand Down
5 changes: 3 additions & 2 deletions themes/radial/components/toc.typ
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
#h(5pt)
#entry.title
#box(width: 1fr, line(length: 100%, stroke: (dash: "dotted")))
#entry.page-number
],)
#link((page: entry.global-page-number,x:0mm,y:0mm))[#entry.page-number]
]
,)
})
linebreak()
Expand Down
12 changes: 10 additions & 2 deletions utils.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#import "/globals.typ"

#let sort_entries(entries) = {
return entries.map(entry=>{
if entry.ctx.date == none {entry.ctx.insert("date", datetime(year: 0, day: 1, month: 1))}
return entry
}).sorted(key: entry=>entry.ctx.date)
}

// TODO: document what ctx provides to the callback
/// Utility function to help themes implement a table of contents.
///
Expand Down Expand Up @@ -34,10 +41,11 @@

let result = ()

for (index, entry) in state.final(loc).enumerate() {
let page-number = counter(page).at(markers.at(index).location()).at(0)
for (entry,marker) in sort_entries(state.final(loc)).zip(markers) {
let page-number = counter(page).at(marker.location()).at(0)
let ctx = entry.ctx
ctx.page-number = page-number
ctx.global-page-number = marker.location().page()
result.push(ctx)
}
return result
Expand Down

0 comments on commit 75c7a51

Please sign in to comment.