-
-
Notifications
You must be signed in to change notification settings - Fork 215
/
getConvertOptions.ts
77 lines (68 loc) · 3.31 KB
/
getConvertOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import extend from "extend";
import Promise from "../../utils/promise";
import getPDFTemplate from "./getPDFTemplate";
import getCoverPath from "./getCoverPath";
/**
Generate options for ebook-convert
@param {Output}
@return {Promise<Object>}
*/
function getConvertOptions(output) {
const options = output.getOptions();
const format = options.get("format");
const book = output.getBook();
const config = book.getConfig();
return Promise().then(() => {
const coverPath = getCoverPath(output);
let options = {
"--cover": coverPath,
"--title": config.getValue("title"),
"--comments": config.getValue("description"),
"--isbn": config.getValue("isbn"),
"--authors": config.getValue("author"),
"--author-sort": config.getValue("authorSort"),
"--language": book.getLanguage() || config.getValue("language"),
"--book-producer": config.getValue("producer") || "HonKit",
"--publisher": config.getValue("publisher") || "HonKit",
"--pubdate": config.getValue("pubdate"),
"--series": config.getValue("series"),
"--series-index": config.getValue("seriesIndex"),
"--chapter": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter ')]",
"--level1-toc":
"descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-1 ')]",
"--level2-toc":
"descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-2 ')]",
"--level3-toc":
"descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-3 ')]",
"--max-levels": "1",
"--no-chapters-in-toc": true,
"--breadth-first": true,
"--dont-split-on-page-breaks": format === "epub" ? true : undefined,
};
if (format !== "pdf") {
return options;
}
return Promise.all([getPDFTemplate(output, "header"), getPDFTemplate(output, "footer")]).spread(
(headerTpl, footerTpl) => {
const pdfOptions = config.getValue("pdf").toJS();
return (options = extend(options, {
"--chapter-mark": String(pdfOptions.chapterMark),
"--page-breaks-before": String(pdfOptions.pageBreaksBefore),
"--margin-left": String(pdfOptions.margin.left),
"--margin-right": String(pdfOptions.margin.right),
"--margin-top": String(pdfOptions.margin.top),
"--margin-bottom": String(pdfOptions.margin.bottom),
"--pdf-default-font-size": String(pdfOptions.fontSize),
"--pdf-mono-font-size": String(pdfOptions.fontSize),
"--paper-size": String(pdfOptions.paperSize),
"--pdf-page-numbers": Boolean(pdfOptions.pageNumbers),
"--pdf-sans-family": String(pdfOptions.fontFamily),
"--pdf-header-template": headerTpl,
"--pdf-footer-template": footerTpl,
"--embed-all-fonts": Boolean(pdfOptions.embedFonts),
}));
}
);
});
}
export default getConvertOptions;