UNPKG

honkit

Version:

HonKit is building beautiful books using Markdown.

43 lines (41 loc) 1.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const juice_1 = __importDefault(require("juice")); const website_1 = __importDefault(require("../website")); const json_1 = __importDefault(require("../../json")); const templating_1 = __importDefault(require("../../templating")); const promise_1 = __importDefault(require("../../utils/promise")); /** Generate PDF header/footer templates @param {Output} output @param {string} type @return {string} */ function getPDFTemplate(output, type) { const filePath = `pdf_${type}.html`; const outputRoot = output.getRoot(); const engine = website_1.default.createTemplateEngine(output, filePath); // Generate context const context = json_1.default.encodeOutput(output); // @ts-expect-error ts-migrate(2339) FIXME: Property 'page' does not exist on type '{ summary:... Remove this comment to see the full error message context.page = { num: "_PAGENUM_", title: "_SECTION_" }; // Render the theme return (templating_1.default.renderFile(engine, `ebook/${filePath}`, context) // Inline css and assets .then((tplOut) => { return promise_1.default.nfcall(juice_1.default.juiceResources, tplOut.getContent(), { webResources: { relativeTo: outputRoot } }); }) .then((tplOut) => tplOut.replace(/\n/g, " ")) // PDF templates need to be on one line for inclusion in spawned command ); } exports.default = getPDFTemplate;