UNPKG

honkit

Version:

HonKit is building beautiful books using Markdown.

81 lines (78 loc) 2.42 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const immutable_1 = __importDefault(require("immutable")); const timing_1 = __importDefault(require("../utils/timing")); const page_1 = __importDefault(require("../models/page")); const walkSummary_1 = __importDefault(require("./walkSummary")); const parsePage_1 = __importDefault(require("./parsePage")); /** Parse a page from a path @param {Book} book @param {string} filePath @return {Page?} */ function parseFilePage(book, filePath) { const fs = book.getContentFS(); return fs .statFile(filePath) .then((file) => { const page = page_1.default.createForFile(file); return (0, parsePage_1.default)(book, page); }, (err) => { // file doesn't exist return null; }) .fail((err) => { const logger = book.getLogger(); logger.error.ln(`error while parsing page "${filePath}":`); throw err; }); } /** Parse all pages from a book as an OrderedMap @param {Book} book @return {Promise<OrderedMap<Page>>} */ function parsePagesList(book) { const summary = book.getSummary(); const glossary = book.getGlossary(); let map = immutable_1.default.OrderedMap(); // Parse pages from summary return (timing_1.default .measure("parse.listPages", (0, walkSummary_1.default)(summary, (article) => { if (!article.isPage()) return; const filepath = article.getPath(); // Is the page ignored? if (book.isContentFileIgnored(filepath)) return; return parseFilePage(book, filepath).then((page) => { // file doesn't exist if (!page) { return; } map = map.set(filepath, page); }); })) // Parse glossary .then(() => { const file = glossary.getFile(); if (!file.exists()) { return; } return parseFilePage(book, file.getPath()).then((page) => { // file doesn't exist if (!page) { return; } map = map.set(file.getPath(), page); }); }) .then(() => { return map; })); } exports.default = parsePagesList;