mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 11:07:04 +00:00
changes
This commit is contained in:
1 parent
0e0d334f6a
commit
aa44696803
1 file changed
+15
-6
+15
-6
@@ -152,7 +152,10 @@ function preamble(book: Book): string {
|
|||||||
#let contents() = {
|
#let contents() = {
|
||||||
pagebreak(weak: true)
|
pagebreak(weak: true)
|
||||||
set par(justify: false, first-line-indent: 0pt)
|
set par(justify: false, first-line-indent: 0pt)
|
||||||
block(below: 2em)[#text(font: "Literata", size: 24pt, weight: "medium")[Contents]]
|
block(below: 2em)[
|
||||||
|
#show heading: set block(above: 0pt, below: 0pt)
|
||||||
|
#heading(level: 1, numbering: none, outlined: false, bookmarked: true)[#text(font: "Literata", size: 24pt, weight: "medium")[Contents]]
|
||||||
|
]
|
||||||
context {
|
context {
|
||||||
let items = query(<chap>).filter(it => it.value.toc != false)
|
let items = query(<chap>).filter(it => it.value.toc != false)
|
||||||
let prev = none
|
let prev = none
|
||||||
@@ -254,13 +257,18 @@ function normTitle(title: string): string {
|
|||||||
return cleanTitle(title).toLowerCase();
|
return cleanTitle(title).toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function inToc(book: Book, index: number): boolean {
|
||||||
|
const chapter = book.chapters[index];
|
||||||
|
const title = cleanTitle(chapter.title) || "Untitled";
|
||||||
|
return !(chapterKind(chapter) === "front" && normTitle(title) === normTitle(book.metadata.title));
|
||||||
|
}
|
||||||
|
|
||||||
function openerCall(book: Book, index: number): string {
|
function openerCall(book: Book, index: number): string {
|
||||||
const chapter = book.chapters[index];
|
const chapter = book.chapters[index];
|
||||||
const kind = chapterKind(chapter);
|
const kind = chapterKind(chapter);
|
||||||
const num = kind === "body" ? String(bodyNumber(book.chapters, index)) : "";
|
const num = kind === "body" ? String(bodyNumber(book.chapters, index)) : "";
|
||||||
const title = cleanTitle(chapter.title) || "Untitled";
|
const title = cleanTitle(chapter.title) || "Untitled";
|
||||||
const inToc = !(kind === "front" && normTitle(title) === normTitle(book.metadata.title));
|
return `#openchapter((kind: ${str(kind)}, num: ${str(num)}, title: ${str(title)}, toc: ${inToc(book, index)}))`;
|
||||||
return `#openchapter((kind: ${str(kind)}, num: ${str(num)}, title: ${str(title)}, toc: ${inToc}))`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bookToTypst(book: Book, paths: Map<string, string> = new Map(), coverPath?: string): string {
|
export function bookToTypst(book: Book, paths: Map<string, string> = new Map(), coverPath?: string): string {
|
||||||
@@ -270,15 +278,16 @@ export function bookToTypst(book: Book, paths: Map<string, string> = new Map(),
|
|||||||
#titlepage(${str(meta.title || "Untitled")}, ${str(meta.subtitle)}, ${str(meta.author)})
|
#titlepage(${str(meta.title || "Untitled")}, ${str(meta.subtitle)}, ${str(meta.author)})
|
||||||
#pagebreak(weak: true)
|
#pagebreak(weak: true)
|
||||||
#set page(numbering: "i")
|
#set page(numbering: "i")
|
||||||
#counter(page).update(1)
|
#counter(page).update(1)`;
|
||||||
#contents()`;
|
|
||||||
|
|
||||||
const firstBody = book.chapters.findIndex((c) => chapterKind(c) === "body");
|
const firstBody = book.chapters.findIndex((c) => chapterKind(c) === "body");
|
||||||
|
const firstToc = book.chapters.findIndex((_, i) => inToc(book, i));
|
||||||
|
|
||||||
const body = book.chapters
|
const body = book.chapters
|
||||||
.map((chapter, i) => {
|
.map((chapter, i) => {
|
||||||
|
const toc = i === firstToc ? `#contents()\n\n` : "";
|
||||||
const reset = i === firstBody ? `#set page(numbering: "1")\n#counter(page).update(1)\n` : "";
|
const reset = i === firstBody ? `#set page(numbering: "1")\n#counter(page).update(1)\n` : "";
|
||||||
return `${reset}${openerCall(book, i)}\n\n${chapterBody(chapter.content, paths)}`;
|
return `${toc}${reset}${openerCall(book, i)}\n\n${chapterBody(chapter.content, paths)}`;
|
||||||
})
|
})
|
||||||
.join("\n\n");
|
.join("\n\n");
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user