honkit
Version:
HonKit is building beautiful books using Markdown.
37 lines (36 loc) • 1.66 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.onPage = onPage;
const json_1 = __importDefault(require("../../json"));
const path_1 = __importDefault(require("../../utils/path"));
const modifiers_1 = __importDefault(require("../modifiers"));
const writeFile_1 = __importDefault(require("../helper/writeFile"));
const getModifiers_1 = __importDefault(require("../getModifiers"));
const JSON_VERSION = "3";
/**
* Write a page as a json file
*
* @param {Output} output
* @param {Page} page
*/
function onPage(output, page) {
const file = page.getFile();
const readme = output.getBook().getReadme().getFile();
return modifiers_1.default.modifyHTML(page, (0, getModifiers_1.default)(output, page)).then((resultPage) => {
// Generate the JSON
const json = json_1.default.encodeBookWithPage(output.getBook(), resultPage);
// Delete some private properties
delete json.config;
// Specify JSON output version
// @ts-expect-error ts-migrate(2339) FIXME: Property 'version' does not exist on type '{ summa... Remove this comment to see the full error message
json.version = JSON_VERSION;
// File path in the output folder
let filePath = file.getPath() == readme.getPath() ? "README.json" : file.getPath();
filePath = path_1.default.setExtension(filePath, ".json");
// Write it to the disk
return (0, writeFile_1.default)(output, filePath, JSON.stringify(json, null, 4));
});
}