UNPKG

honkit

Version:

HonKit is building beautiful books using Markdown.

73 lines (72 loc) 3.77 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.onPage = onPage; const path_1 = __importDefault(require("path")); const omit_keys_1 = __importDefault(require("omit-keys")); const templating_1 = __importDefault(require("../../templating")); const plugins_1 = __importDefault(require("../../plugins")); const json_1 = __importDefault(require("../../json")); const location_1 = __importDefault(require("../../utils/location")); const modifiers_1 = __importDefault(require("../modifiers")); const writeFile_1 = __importDefault(require("../helper/writeFile")); const getModifiers_1 = __importDefault(require("../getModifiers")); const createTemplateEngine_1 = __importDefault(require("./createTemplateEngine")); const fileToOutput_1 = __importDefault(require("../helper/fileToOutput")); /** * Write a page as a json file * * @param {Output} output * @param {Page} page */ function onPage(output, page) { const options = output.getOptions(); const prefix = options.get("prefix"); const file = page.getFile(); const book = output.getBook(); const plugins = output.getPlugins(); const state = output.getState(); const resources = state.getResources(); const engine = (0, createTemplateEngine_1.default)(output, page.getPath()); // Output file path const filePath = (0, fileToOutput_1.default)(output, file.getPath()); // Calcul relative path to the root const outputDirName = path_1.default.dirname(filePath); const basePath = location_1.default.normalize(path_1.default.relative(outputDirName, "./")); return modifiers_1.default.modifyHTML(page, (0, getModifiers_1.default)(output, page)).then((resultPage) => { // Generate the context const context = json_1.default.encodeOutputWithPage(output, resultPage); // @ts-expect-error ts-migrate(2339) FIXME: Property 'plugins' does not exist on type '{ summa... Remove this comment to see the full error message context.plugins = { resources: plugins_1.default.listResources(plugins, resources).toJS() }; // @ts-expect-error ts-migrate(2339) FIXME: Property 'template' does not exist on type '{ summ... Remove this comment to see the full error message context.template = { getJSContext: function () { return { // @ts-expect-error ts-migrate(2339) FIXME: Property 'page' does not exist on type '{ summary:... Remove this comment to see the full error message page: (0, omit_keys_1.default)(context.page, "content"), config: context.config, // @ts-expect-error ts-migrate(2339) FIXME: Property 'file' does not exist on type '{ summary:... Remove this comment to see the full error message file: context.file, gitbook: context.gitbook, basePath: basePath, book: { language: book.getLanguage() } }; } }; // We should probabbly move it to "template" or a "site" namespace // @ts-expect-error ts-migrate(2339) FIXME: Property 'basePath' does not exist on type '{ summ... Remove this comment to see the full error message context.basePath = basePath; // Render the theme return (templating_1.default.renderFile(engine, `${prefix}/page.html`, context) // Write it to the disk .then((tplOut) => { return (0, writeFile_1.default)(output, filePath, tplOut.getContent()); })); }); }