mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-03 03:27:03 +00:00
changes
This commit is contained in:
1 parent
734ded73ac
commit
c86d5a7d5c
14 files changed
+671
-86
No files matched your search
+11
-8
@@ -1,6 +1,6 @@
|
||||
import type { JSONContent } from "@tiptap/core";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { type Book, TRIM_DIMS } from "../model/book";
|
||||
import { type Book, TRIM_DIMS, bodyNumber, chapterKind } from "../model/book";
|
||||
|
||||
export interface EpubFile {
|
||||
path: string;
|
||||
@@ -277,10 +277,10 @@ function contentOpf(
|
||||
|
||||
function navXhtml(book: Book): string {
|
||||
const items = book.chapters
|
||||
.map(
|
||||
(chapter, i) =>
|
||||
` <li><a href="chapter-${i + 1}.xhtml">${esc(chapter.title || `Chapter ${i + 1}`)}</a></li>`,
|
||||
)
|
||||
.map((chapter, i) => {
|
||||
const fallback = chapterKind(chapter) === "body" ? `Chapter ${bodyNumber(book.chapters, i)}` : "Untitled";
|
||||
return ` <li><a href="chapter-${i + 1}.xhtml">${esc(chapter.title || fallback)}</a></li>`;
|
||||
})
|
||||
.join("\n");
|
||||
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="${attr(book.metadata.language || "en")}">
|
||||
@@ -301,16 +301,19 @@ ${items}
|
||||
|
||||
function chapterXhtml(book: Book, index: number, paths: Map<string, string>): string {
|
||||
const chapter = book.chapters[index];
|
||||
const title = chapter.title || `Chapter ${index + 1}`;
|
||||
const kind = chapterKind(chapter);
|
||||
const num = bodyNumber(book.chapters, index);
|
||||
const title = chapter.title || (kind === "body" ? `Chapter ${num}` : "Untitled");
|
||||
const eyebrow = kind === "body" ? `<p class="eyebrow">Chapter ${num}</p>` : "";
|
||||
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="${attr(book.metadata.language || "en")}">
|
||||
<head>
|
||||
<title>${esc(title)}</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css"/>
|
||||
</head>
|
||||
<body epub:type="chapter">
|
||||
<body epub:type="${kind === "body" ? "chapter" : kind === "front" ? "frontmatter" : "backmatter"}">
|
||||
<header class="chapter-opener">
|
||||
<p class="eyebrow">Chapter ${index + 1}</p>
|
||||
${eyebrow}
|
||||
<h1>${esc(title)}</h1>
|
||||
</header>
|
||||
${chapterBody(chapter.content, paths)}
|
||||
|
||||
+18
-3
@@ -1,5 +1,5 @@
|
||||
import type { JSONContent } from "@tiptap/core";
|
||||
import type { Book, TrimSize } from "../model/book";
|
||||
import { type Book, type TrimSize, bodyNumber, chapterKind } from "../model/book";
|
||||
import type { ImageInput } from "../ipc";
|
||||
|
||||
const TRIM: Record<TrimSize, { w: string; h: string }> = {
|
||||
@@ -136,6 +136,15 @@ function preamble(book: Book): string {
|
||||
#heading(level: 1, numbering: none, outlined: true)[#title]
|
||||
]
|
||||
v(1.5em)
|
||||
}
|
||||
|
||||
#let pageopener(title) = {
|
||||
pagebreak(weak: true)
|
||||
v(2.1in)
|
||||
align(center)[
|
||||
#heading(level: 1, numbering: none, outlined: true)[#title]
|
||||
]
|
||||
v(1.5em)
|
||||
}`;
|
||||
}
|
||||
|
||||
@@ -216,7 +225,10 @@ export function bookToTypst(book: Book, paths: Map<string, string> = new Map(),
|
||||
|
||||
const body = book.chapters
|
||||
.map((chapter, i) => {
|
||||
const opener = `#chapteropener(${str(String(i + 1))}, [${esc(chapter.title || "Untitled")}])`;
|
||||
const opener =
|
||||
chapterKind(chapter) === "body"
|
||||
? `#chapteropener(${str(String(bodyNumber(book.chapters, i)))}, [${esc(chapter.title || "Untitled")}])`
|
||||
: `#pageopener([${esc(chapter.title || "Untitled")}])`;
|
||||
return `${opener}\n\n${chapterBody(chapter.content, paths)}`;
|
||||
})
|
||||
.join("\n\n");
|
||||
@@ -238,7 +250,10 @@ export function coverToPdfInputs(book: Book): { source: string; images: ImageInp
|
||||
|
||||
function chapterToTypst(book: Book, index: number, paths: Map<string, string>): string {
|
||||
const chapter = book.chapters[index];
|
||||
const opener = `#chapteropener(${str(String(index + 1))}, [${esc(chapter.title || "Untitled")}])`;
|
||||
const opener =
|
||||
chapterKind(chapter) === "body"
|
||||
? `#chapteropener(${str(String(bodyNumber(book.chapters, index)))}, [${esc(chapter.title || "Untitled")}])`
|
||||
: `#pageopener([${esc(chapter.title || "Untitled")}])`;
|
||||
return `${preamble(book)}
|
||||
|
||||
#set page(numbering: "1")
|
||||
|
||||
Reference in new issue
Block a user