honkit 3.6.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +10 -0
- package/bin/honkit.js +8 -0
- package/lib/BuildGenerator.js +2 -0
- package/lib/__tests__/__fixtures__/honkit/book.js +9 -0
- package/lib/__tests__/githon.js +11 -0
- package/lib/__tests__/init.js +19 -0
- package/lib/__tests__/snapshot-honkit.js +45 -0
- package/lib/api/decodeConfig.js +17 -0
- package/lib/api/decodeGlobal.js +21 -0
- package/lib/api/decodePage.js +41 -0
- package/lib/api/deprecate.js +113 -0
- package/lib/api/encodeConfig.js +30 -0
- package/lib/api/encodeGlobal.js +226 -0
- package/lib/api/encodeNavigation.js +60 -0
- package/lib/api/encodePage.js +37 -0
- package/lib/api/encodeProgress.js +58 -0
- package/lib/api/encodeSummary.js +52 -0
- package/lib/api/index.js +15 -0
- package/lib/bin.js +46 -0
- package/lib/browser.js +41 -0
- package/lib/cli/build.js +36 -0
- package/lib/cli/buildEbook.js +63 -0
- package/lib/cli/getBook.js +24 -0
- package/lib/cli/getOutputFolder.js +19 -0
- package/lib/cli/index.js +11 -0
- package/lib/cli/init.js +17 -0
- package/lib/cli/options.js +38 -0
- package/lib/cli/parse.js +65 -0
- package/lib/cli/serve.js +184 -0
- package/lib/cli/server.js +116 -0
- package/lib/cli/watch.js +35 -0
- package/lib/constants/__tests__/configSchema.js +41 -0
- package/lib/constants/configDefault.js +9 -0
- package/lib/constants/configFiles.js +3 -0
- package/lib/constants/configSchema.js +235 -0
- package/lib/constants/defaultBlocks.js +48 -0
- package/lib/constants/defaultFilters.js +18 -0
- package/lib/constants/defaultPlugins.js +20 -0
- package/lib/constants/extsAsciidoc.js +3 -0
- package/lib/constants/extsMarkdown.js +3 -0
- package/lib/constants/ignoreFiles.js +3 -0
- package/lib/constants/pluginAssetsFolder.js +3 -0
- package/lib/constants/pluginHooks.js +3 -0
- package/lib/constants/pluginPrefix.js +3 -0
- package/lib/constants/pluginResources.js +7 -0
- package/lib/constants/templatesFolder.js +3 -0
- package/lib/constants/themePrefix.js +3 -0
- package/lib/fs/__tests__/mock.js +68 -0
- package/lib/fs/mock.js +88 -0
- package/lib/fs/node.js +44 -0
- package/lib/honkit.js +34 -0
- package/lib/index.js +17 -0
- package/lib/init.js +79 -0
- package/lib/json/encodeBook.js +41 -0
- package/lib/json/encodeBookWithPage.js +25 -0
- package/lib/json/encodeFile.js +20 -0
- package/lib/json/encodeGlossary.js +22 -0
- package/lib/json/encodeGlossaryEntry.js +16 -0
- package/lib/json/encodeLanguages.js +29 -0
- package/lib/json/encodeOutput.js +26 -0
- package/lib/json/encodeOutputWithPage.js +26 -0
- package/lib/json/encodePage.js +38 -0
- package/lib/json/encodeReadme.js +19 -0
- package/lib/json/encodeSummary.js +22 -0
- package/lib/json/encodeSummaryArticle.js +25 -0
- package/lib/json/encodeSummaryPart.js +19 -0
- package/lib/json/index.js +27 -0
- package/lib/models/__tests__/config.js +164 -0
- package/lib/models/__tests__/glossary.js +38 -0
- package/lib/models/__tests__/glossaryEntry.js +16 -0
- package/lib/models/__tests__/page.js +26 -0
- package/lib/models/__tests__/plugin.js +26 -0
- package/lib/models/__tests__/pluginDependency.js +71 -0
- package/lib/models/__tests__/summary.js +115 -0
- package/lib/models/__tests__/summaryArticle.js +62 -0
- package/lib/models/__tests__/summaryPart.js +24 -0
- package/lib/models/__tests__/templateBlock.js +172 -0
- package/lib/models/__tests__/templateEngine.js +49 -0
- package/lib/models/book.js +312 -0
- package/lib/models/config.js +152 -0
- package/lib/models/file.js +83 -0
- package/lib/models/fs.js +255 -0
- package/lib/models/glossary.js +90 -0
- package/lib/models/glossaryEntry.js +34 -0
- package/lib/models/hash.js +191 -0
- package/lib/models/ignore.js +40 -0
- package/lib/models/language.js +22 -0
- package/lib/models/languages.js +64 -0
- package/lib/models/output.js +109 -0
- package/lib/models/page.js +91 -0
- package/lib/models/parser.js +102 -0
- package/lib/models/plugin.js +139 -0
- package/lib/models/pluginDependency.js +192 -0
- package/lib/models/readme.js +38 -0
- package/lib/models/summary.js +199 -0
- package/lib/models/summaryArticle.js +169 -0
- package/lib/models/summaryPart.js +53 -0
- package/lib/models/templateBlock.js +230 -0
- package/lib/models/templateEngine.js +115 -0
- package/lib/models/templateOutput.js +36 -0
- package/lib/models/templateShortcut.js +65 -0
- package/lib/modifiers/config/__tests__/addPlugin.js +30 -0
- package/lib/modifiers/config/__tests__/removePlugin.js +29 -0
- package/lib/modifiers/config/__tests__/togglePlugin.js +28 -0
- package/lib/modifiers/config/addPlugin.js +27 -0
- package/lib/modifiers/config/editPlugin.js +13 -0
- package/lib/modifiers/config/getPluginConfig.js +22 -0
- package/lib/modifiers/config/hasPlugin.js +15 -0
- package/lib/modifiers/config/index.js +21 -0
- package/lib/modifiers/config/isDefaultPlugin.js +17 -0
- package/lib/modifiers/config/removePlugin.js +27 -0
- package/lib/modifiers/config/togglePlugin.js +32 -0
- package/lib/modifiers/index.js +11 -0
- package/lib/modifiers/summary/__tests__/editPartTitle.js +41 -0
- package/lib/modifiers/summary/__tests__/insertArticle.js +72 -0
- package/lib/modifiers/summary/__tests__/insertPart.js +56 -0
- package/lib/modifiers/summary/__tests__/mergeAtLevel.js +45 -0
- package/lib/modifiers/summary/__tests__/moveArticle.js +66 -0
- package/lib/modifiers/summary/__tests__/moveArticleAfter.js +75 -0
- package/lib/modifiers/summary/__tests__/removeArticle.js +54 -0
- package/lib/modifiers/summary/editArticleRef.js +20 -0
- package/lib/modifiers/summary/editArticleTitle.js +20 -0
- package/lib/modifiers/summary/editPartTitle.js +21 -0
- package/lib/modifiers/summary/index.js +27 -0
- package/lib/modifiers/summary/indexArticleLevels.js +21 -0
- package/lib/modifiers/summary/indexLevels.js +18 -0
- package/lib/modifiers/summary/indexPartLevels.js +25 -0
- package/lib/modifiers/summary/insertArticle.js +47 -0
- package/lib/modifiers/summary/insertPart.js +21 -0
- package/lib/modifiers/summary/mergeAtLevel.js +68 -0
- package/lib/modifiers/summary/moveArticle.js +27 -0
- package/lib/modifiers/summary/moveArticleAfter.js +59 -0
- package/lib/modifiers/summary/removeArticle.js +36 -0
- package/lib/modifiers/summary/removePart.js +18 -0
- package/lib/modifiers/summary/unshiftArticle.js +27 -0
- package/lib/output/__tests__/ebook.js +17 -0
- package/lib/output/__tests__/json.js +43 -0
- package/lib/output/__tests__/plugin-hooks.js +57 -0
- package/lib/output/__tests__/website.js +121 -0
- package/lib/output/callHook.js +51 -0
- package/lib/output/callPageHook.js +23 -0
- package/lib/output/createTemplateEngine.js +42 -0
- package/lib/output/ebook/getConvertOptions.js +69 -0
- package/lib/output/ebook/getCoverPath.js +30 -0
- package/lib/output/ebook/getPDFTemplate.js +40 -0
- package/lib/output/ebook/index.js +16 -0
- package/lib/output/ebook/onFinish.js +84 -0
- package/lib/output/ebook/onPage.js +23 -0
- package/lib/output/ebook/options.js +17 -0
- package/lib/output/generateAssets.js +26 -0
- package/lib/output/generateBook.js +167 -0
- package/lib/output/generatePage.js +90 -0
- package/lib/output/generatePages.js +52 -0
- package/lib/output/getModifiers.js +63 -0
- package/lib/output/helper/fileToOutput.js +30 -0
- package/lib/output/helper/fileToURL.js +30 -0
- package/lib/output/helper/index.js +3 -0
- package/lib/output/helper/resolveFileToURL.js +25 -0
- package/lib/output/helper/writeFile.js +26 -0
- package/lib/output/index.js +27 -0
- package/lib/output/json/index.js +14 -0
- package/lib/output/json/onFinish.js +39 -0
- package/lib/output/json/onPage.js +37 -0
- package/lib/output/json/options.js +11 -0
- package/lib/output/modifiers/__tests__/addHeadingId.js +23 -0
- package/lib/output/modifiers/__tests__/annotateText.js +39 -0
- package/lib/output/modifiers/__tests__/fetchRemoteImages.js +32 -0
- package/lib/output/modifiers/__tests__/highlightCode.js +48 -0
- package/lib/output/modifiers/__tests__/inlinePng.js +22 -0
- package/lib/output/modifiers/__tests__/inlineSvg.js +42 -0
- package/lib/output/modifiers/__tests__/resolveImages.js +39 -0
- package/lib/output/modifiers/__tests__/resolveLinks.js +81 -0
- package/lib/output/modifiers/__tests__/svgToImg.js +29 -0
- package/lib/output/modifiers/addHeadingId.js +26 -0
- package/lib/output/modifiers/annotateText.js +76 -0
- package/lib/output/modifiers/editHTMLElement.js +17 -0
- package/lib/output/modifiers/fetchRemoteImages.js +42 -0
- package/lib/output/modifiers/highlightCode.js +59 -0
- package/lib/output/modifiers/index.js +26 -0
- package/lib/output/modifiers/inlineAssets.js +29 -0
- package/lib/output/modifiers/inlinePng.js +43 -0
- package/lib/output/modifiers/inlineSvg.js +39 -0
- package/lib/output/modifiers/modifyHTML.js +27 -0
- package/lib/output/modifiers/resolveImages.js +30 -0
- package/lib/output/modifiers/resolveLinks.js +46 -0
- package/lib/output/modifiers/svgToImg.js +58 -0
- package/lib/output/page-cache.js +15 -0
- package/lib/output/prepareAssets.js +22 -0
- package/lib/output/preparePages.js +25 -0
- package/lib/output/preparePlugins.js +36 -0
- package/lib/output/testing/createMock.js +39 -0
- package/lib/output/testing/generateMock.js +55 -0
- package/lib/output/website/__tests__/i18n.js +40 -0
- package/lib/output/website/copyPluginAssets.js +92 -0
- package/lib/output/website/createTemplateEngine.js +136 -0
- package/lib/output/website/index.js +22 -0
- package/lib/output/website/listSearchPaths.js +20 -0
- package/lib/output/website/onAsset.js +29 -0
- package/lib/output/website/onFinish.js +35 -0
- package/lib/output/website/onInit.js +19 -0
- package/lib/output/website/onPage.js +73 -0
- package/lib/output/website/options.js +15 -0
- package/lib/output/website/prepareI18n.js +28 -0
- package/lib/output/website/prepareResources.js +49 -0
- package/lib/output/website/state.js +20 -0
- package/lib/parse/__tests__/listAssets.js +63 -0
- package/lib/parse/__tests__/parseBook.js +77 -0
- package/lib/parse/__tests__/parseGlossary.js +32 -0
- package/lib/parse/__tests__/parseIgnore.js +37 -0
- package/lib/parse/__tests__/parsePageFromString.js +34 -0
- package/lib/parse/__tests__/parseReadme.js +33 -0
- package/lib/parse/__tests__/parseSummary.js +30 -0
- package/lib/parse/findParsableFile.js +33 -0
- package/lib/parse/index.js +31 -0
- package/lib/parse/listAssets.js +36 -0
- package/lib/parse/lookupStructureFile.js +21 -0
- package/lib/parse/parseBook.js +68 -0
- package/lib/parse/parseConfig.js +52 -0
- package/lib/parse/parseGlossary.js +25 -0
- package/lib/parse/parseIgnore.js +43 -0
- package/lib/parse/parseLanguages.js +26 -0
- package/lib/parse/parsePage.js +21 -0
- package/lib/parse/parsePageFromString.js +25 -0
- package/lib/parse/parsePagesList.js +80 -0
- package/lib/parse/parseReadme.js +26 -0
- package/lib/parse/parseStructureFile.js +64 -0
- package/lib/parse/parseSummary.js +43 -0
- package/lib/parse/validateConfig.js +31 -0
- package/lib/parse/walkSummary.js +34 -0
- package/lib/parsers.js +60 -0
- package/lib/plugins/PluginResolver.js +84 -0
- package/lib/plugins/__tests__/findInstalled.js +25 -0
- package/lib/plugins/__tests__/listDependencies.js +28 -0
- package/lib/plugins/__tests__/sortDependencies.js +28 -0
- package/lib/plugins/__tests__/validatePlugin.js +99 -0
- package/lib/plugins/findInstalled.js +87 -0
- package/lib/plugins/index.js +17 -0
- package/lib/plugins/listBlocks.js +19 -0
- package/lib/plugins/listDependencies.js +33 -0
- package/lib/plugins/listDepsForBook.js +20 -0
- package/lib/plugins/listFilters.js +18 -0
- package/lib/plugins/listResources.js +44 -0
- package/lib/plugins/loadForBook.js +38 -0
- package/lib/plugins/loadPlugin.js +89 -0
- package/lib/plugins/package-name-util.js +48 -0
- package/lib/plugins/sortDependencies.js +30 -0
- package/lib/plugins/toNames.js +16 -0
- package/lib/plugins/validateConfig.js +60 -0
- package/lib/plugins/validatePlugin.js +36 -0
- package/lib/templating/__tests__/conrefsLoader.js +93 -0
- package/lib/templating/__tests__/postRender.js +52 -0
- package/lib/templating/__tests__/replaceShortcuts.js +27 -0
- package/lib/templating/conrefsLoader.js +88 -0
- package/lib/templating/index.js +19 -0
- package/lib/templating/listShortcuts.js +29 -0
- package/lib/templating/postRender.js +46 -0
- package/lib/templating/render.js +41 -0
- package/lib/templating/renderFile.js +39 -0
- package/lib/templating/replaceShortcuts.js +36 -0
- package/lib/templating/themesLoader.js +98 -0
- package/lib/utils/__tests__/git.js +47 -0
- package/lib/utils/__tests__/location.js +81 -0
- package/lib/utils/__tests__/path.js +19 -0
- package/lib/utils/command.js +104 -0
- package/lib/utils/error.js +88 -0
- package/lib/utils/fs.js +163 -0
- package/lib/utils/genKey.js +13 -0
- package/lib/utils/git.js +116 -0
- package/lib/utils/images.js +22 -0
- package/lib/utils/location.js +129 -0
- package/lib/utils/logger.js +158 -0
- package/lib/utils/mergeDefaults.js +18 -0
- package/lib/utils/path.js +62 -0
- package/lib/utils/promise.js +142 -0
- package/lib/utils/reducedObject.js +31 -0
- package/lib/utils/timing.js +90 -0
- package/package.json +112 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_1 = __importDefault(require("../../utils/fs"));
|
|
8
|
+
/**
|
|
9
|
+
Resolve path to cover file to use
|
|
10
|
+
|
|
11
|
+
@param {Output}
|
|
12
|
+
@return {string}
|
|
13
|
+
*/
|
|
14
|
+
function getCoverPath(output) {
|
|
15
|
+
const outputRoot = output.getRoot();
|
|
16
|
+
const book = output.getBook();
|
|
17
|
+
const config = book.getConfig();
|
|
18
|
+
const coverName = config.getValue("cover", "cover.jpg");
|
|
19
|
+
// Resolve to absolute
|
|
20
|
+
let cover = fs_1.default.pickFile(outputRoot, coverName);
|
|
21
|
+
if (cover) {
|
|
22
|
+
return cover;
|
|
23
|
+
}
|
|
24
|
+
// Multilingual? try parent folder
|
|
25
|
+
if (book.isLanguageBook()) {
|
|
26
|
+
cover = fs_1.default.pickFile(path_1.default.join(outputRoot, ".."), coverName);
|
|
27
|
+
}
|
|
28
|
+
return cover;
|
|
29
|
+
}
|
|
30
|
+
exports.default = getCoverPath;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const juice_1 = __importDefault(require("juice"));
|
|
7
|
+
const website_1 = __importDefault(require("../website"));
|
|
8
|
+
const json_1 = __importDefault(require("../../json"));
|
|
9
|
+
const templating_1 = __importDefault(require("../../templating"));
|
|
10
|
+
const promise_1 = __importDefault(require("../../utils/promise"));
|
|
11
|
+
/**
|
|
12
|
+
Generate PDF header/footer templates
|
|
13
|
+
|
|
14
|
+
@param {Output} output
|
|
15
|
+
@param {string} type
|
|
16
|
+
@return {string}
|
|
17
|
+
*/
|
|
18
|
+
function getPDFTemplate(output, type) {
|
|
19
|
+
const filePath = `pdf_${type}.html`;
|
|
20
|
+
const outputRoot = output.getRoot();
|
|
21
|
+
const engine = website_1.default.createTemplateEngine(output, filePath);
|
|
22
|
+
// Generate context
|
|
23
|
+
const context = json_1.default.encodeOutput(output);
|
|
24
|
+
// @ts-expect-error ts-migrate(2339) FIXME: Property 'page' does not exist on type '{ summary:... Remove this comment to see the full error message
|
|
25
|
+
context.page = {
|
|
26
|
+
num: "_PAGENUM_",
|
|
27
|
+
title: "_SECTION_",
|
|
28
|
+
};
|
|
29
|
+
// Render the theme
|
|
30
|
+
return (templating_1.default.renderFile(engine, `ebook/${filePath}`, context)
|
|
31
|
+
// Inline css and assets
|
|
32
|
+
.then((tplOut) => {
|
|
33
|
+
return promise_1.default.nfcall(juice_1.default.juiceResources, tplOut.getContent(), {
|
|
34
|
+
webResources: {
|
|
35
|
+
relativeTo: outputRoot,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
exports.default = getPDFTemplate;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const extend_1 = __importDefault(require("extend"));
|
|
7
|
+
const website_1 = __importDefault(require("../website"));
|
|
8
|
+
const options_1 = __importDefault(require("./options"));
|
|
9
|
+
const onPage_1 = __importDefault(require("./onPage"));
|
|
10
|
+
const onFinish_1 = __importDefault(require("./onFinish"));
|
|
11
|
+
exports.default = extend_1.default({}, website_1.default, {
|
|
12
|
+
name: "ebook",
|
|
13
|
+
Options: options_1.default,
|
|
14
|
+
onPage: onPage_1.default,
|
|
15
|
+
onFinish: onFinish_1.default,
|
|
16
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const website_1 = __importDefault(require("../website"));
|
|
8
|
+
const json_1 = __importDefault(require("../../json"));
|
|
9
|
+
const templating_1 = __importDefault(require("../../templating"));
|
|
10
|
+
const promise_1 = __importDefault(require("../../utils/promise"));
|
|
11
|
+
const error_1 = __importDefault(require("../../utils/error"));
|
|
12
|
+
const command_1 = __importDefault(require("../../utils/command"));
|
|
13
|
+
const writeFile_1 = __importDefault(require("../helper/writeFile"));
|
|
14
|
+
const getConvertOptions_1 = __importDefault(require("./getConvertOptions"));
|
|
15
|
+
const SUMMARY_FILE = "SUMMARY.html";
|
|
16
|
+
/**
|
|
17
|
+
Write the SUMMARY.html
|
|
18
|
+
|
|
19
|
+
@param {Output}
|
|
20
|
+
@return {Output}
|
|
21
|
+
*/
|
|
22
|
+
function writeSummary(output) {
|
|
23
|
+
const options = output.getOptions();
|
|
24
|
+
const prefix = options.get("prefix");
|
|
25
|
+
const filePath = SUMMARY_FILE;
|
|
26
|
+
const engine = website_1.default.createTemplateEngine(output, filePath);
|
|
27
|
+
const context = json_1.default.encodeOutput(output);
|
|
28
|
+
// Render the theme
|
|
29
|
+
return (templating_1.default.renderFile(engine, `${prefix}/summary.html`, context)
|
|
30
|
+
// Write it to the disk
|
|
31
|
+
.then((tplOut) => {
|
|
32
|
+
return writeFile_1.default(output, filePath, tplOut.getContent());
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
Generate the ebook file as "index.pdf"
|
|
37
|
+
|
|
38
|
+
@param {Output}
|
|
39
|
+
@return {Output}
|
|
40
|
+
*/
|
|
41
|
+
function runEbookConvert(output) {
|
|
42
|
+
const logger = output.getLogger();
|
|
43
|
+
const options = output.getOptions();
|
|
44
|
+
const format = options.get("format");
|
|
45
|
+
const outputFolder = output.getRoot();
|
|
46
|
+
if (!format) {
|
|
47
|
+
return promise_1.default(output);
|
|
48
|
+
}
|
|
49
|
+
return getConvertOptions_1.default(output)
|
|
50
|
+
.then((options) => {
|
|
51
|
+
const cmd = [
|
|
52
|
+
"ebook-convert",
|
|
53
|
+
path_1.default.resolve(outputFolder, SUMMARY_FILE),
|
|
54
|
+
path_1.default.resolve(outputFolder, `index.${format}`),
|
|
55
|
+
command_1.default.optionsToShellArgs(options),
|
|
56
|
+
].join(" ");
|
|
57
|
+
return (command_1.default
|
|
58
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
|
59
|
+
.exec(cmd)
|
|
60
|
+
.progress((data) => {
|
|
61
|
+
logger.debug(data);
|
|
62
|
+
})
|
|
63
|
+
.fail((err) => {
|
|
64
|
+
if (err.code == 127) {
|
|
65
|
+
throw error_1.default.RequireInstallError({
|
|
66
|
+
cmd: "ebook-convert",
|
|
67
|
+
install: "Install it from Calibre: https://calibre-ebook.com",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
throw error_1.default.EbookError(err);
|
|
71
|
+
}));
|
|
72
|
+
})
|
|
73
|
+
.thenResolve(output);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
Finish the generation, generates the SUMMARY.html
|
|
77
|
+
|
|
78
|
+
@param {Output}
|
|
79
|
+
@return {Output}
|
|
80
|
+
*/
|
|
81
|
+
function onFinish(output) {
|
|
82
|
+
return writeSummary(output).then(runEbookConvert);
|
|
83
|
+
}
|
|
84
|
+
exports.default = onFinish;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const website_1 = __importDefault(require("../website"));
|
|
7
|
+
const modifiers_1 = __importDefault(require("../modifiers"));
|
|
8
|
+
/**
|
|
9
|
+
Write a page for ebook output
|
|
10
|
+
|
|
11
|
+
@param {Output} output
|
|
12
|
+
@param {Output}
|
|
13
|
+
*/
|
|
14
|
+
function onPage(output, page) {
|
|
15
|
+
const options = output.getOptions();
|
|
16
|
+
// Inline assets
|
|
17
|
+
return (modifiers_1.default.modifyHTML(page, [modifiers_1.default.inlineAssets(options.get("root"), page.getFile().getPath())])
|
|
18
|
+
// Write page using website generator
|
|
19
|
+
.then((resultPage) => {
|
|
20
|
+
return website_1.default.onPage(output, resultPage);
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
exports.default = onPage;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
const Options = immutable_1.default.Record({
|
|
8
|
+
// Root folder for the output
|
|
9
|
+
root: String(),
|
|
10
|
+
// Prefix for generation
|
|
11
|
+
prefix: String("ebook"),
|
|
12
|
+
// Format to generate using ebook-convert
|
|
13
|
+
format: String(),
|
|
14
|
+
// Force use of absolute urls ("index.html" instead of "/")
|
|
15
|
+
directoryIndex: Boolean(false),
|
|
16
|
+
});
|
|
17
|
+
exports.default = Options;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
7
|
+
/**
|
|
8
|
+
Output all assets using a generator
|
|
9
|
+
|
|
10
|
+
@param {Generator} generator
|
|
11
|
+
@param {Output} output
|
|
12
|
+
@return {Promise<Output>}
|
|
13
|
+
*/
|
|
14
|
+
function generateAssets(generator, output) {
|
|
15
|
+
const assets = output.getAssets();
|
|
16
|
+
const logger = output.getLogger();
|
|
17
|
+
// Is generator ignoring assets?
|
|
18
|
+
if (!generator.onAsset) {
|
|
19
|
+
return promise_1.default(output);
|
|
20
|
+
}
|
|
21
|
+
return promise_1.default.reduce(assets, (out, assetFile) => {
|
|
22
|
+
logger.debug.ln(`copy asset "${assetFile}"`);
|
|
23
|
+
return generator.onAsset(out, assetFile);
|
|
24
|
+
}, output);
|
|
25
|
+
}
|
|
26
|
+
exports.default = generateAssets;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.incrementalBuild = exports.generateBook = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
9
|
+
const output_1 = __importDefault(require("../models/output"));
|
|
10
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
11
|
+
const fs_1 = __importDefault(require("../utils/fs"));
|
|
12
|
+
const callHook_1 = __importDefault(require("./callHook"));
|
|
13
|
+
const preparePlugins_1 = __importDefault(require("./preparePlugins"));
|
|
14
|
+
const preparePages_1 = __importDefault(require("./preparePages"));
|
|
15
|
+
const prepareAssets_1 = __importDefault(require("./prepareAssets"));
|
|
16
|
+
const generateAssets_1 = __importDefault(require("./generateAssets"));
|
|
17
|
+
const generatePages_1 = __importDefault(require("./generatePages"));
|
|
18
|
+
/**
|
|
19
|
+
* Process an output to generate the book
|
|
20
|
+
*
|
|
21
|
+
* @param {Generator} generator
|
|
22
|
+
* @param {Output} output
|
|
23
|
+
* @return {Promise<Output>}
|
|
24
|
+
*/
|
|
25
|
+
function processOutput(generator, output) {
|
|
26
|
+
return promise_1.default(output)
|
|
27
|
+
.then(preparePlugins_1.default)
|
|
28
|
+
.then(preparePages_1.default)
|
|
29
|
+
.then(prepareAssets_1.default)
|
|
30
|
+
.then(callHook_1.default.bind(null, "config", (output) => {
|
|
31
|
+
const book = output.getBook();
|
|
32
|
+
const config = book.getConfig();
|
|
33
|
+
const values = config.getValues();
|
|
34
|
+
return values.toJS();
|
|
35
|
+
}, (output, result) => {
|
|
36
|
+
let book = output.getBook();
|
|
37
|
+
let config = book.getConfig();
|
|
38
|
+
config = config.updateValues(result);
|
|
39
|
+
book = book.set("config", config);
|
|
40
|
+
return output.set("book", book);
|
|
41
|
+
}))
|
|
42
|
+
.then(callHook_1.default.bind(null, "init", (output) => {
|
|
43
|
+
return {};
|
|
44
|
+
}, (output) => {
|
|
45
|
+
return output;
|
|
46
|
+
}))
|
|
47
|
+
.then((output) => {
|
|
48
|
+
if (!generator.onInit) {
|
|
49
|
+
return output;
|
|
50
|
+
}
|
|
51
|
+
return generator.onInit(output);
|
|
52
|
+
})
|
|
53
|
+
.then((output) => generateAssets_1.default(generator, output))
|
|
54
|
+
.then((output) => generatePages_1.default(generator, output))
|
|
55
|
+
.tap((output) => {
|
|
56
|
+
const book = output.getBook();
|
|
57
|
+
if (!book.isMultilingual()) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const logger = book.getLogger();
|
|
61
|
+
const books = book.getBooks();
|
|
62
|
+
const outputRoot = output.getRoot();
|
|
63
|
+
const plugins = output.getPlugins();
|
|
64
|
+
const state = output.getState();
|
|
65
|
+
const options = output.getOptions();
|
|
66
|
+
const bookList = books.map((langBook) => {
|
|
67
|
+
// Inherits plugins list, options and state
|
|
68
|
+
const langOptions = options.set("root", path_1.default.join(outputRoot, langBook.getLanguage()));
|
|
69
|
+
const langOutput = new output_1.default({
|
|
70
|
+
book: langBook,
|
|
71
|
+
options: langOptions,
|
|
72
|
+
state: state,
|
|
73
|
+
generator: generator.name,
|
|
74
|
+
plugins: plugins,
|
|
75
|
+
});
|
|
76
|
+
logger.info.ln("");
|
|
77
|
+
logger.info.ln(`generating language "${langBook.getLanguage()}"`);
|
|
78
|
+
return processOutput(generator, langOutput);
|
|
79
|
+
});
|
|
80
|
+
return promise_1.default.all(bookList.toArray()).thenResolve(output);
|
|
81
|
+
})
|
|
82
|
+
.then(callHook_1.default.bind(null, "finish:before", (output) => {
|
|
83
|
+
return {};
|
|
84
|
+
}, (output) => {
|
|
85
|
+
return output;
|
|
86
|
+
}))
|
|
87
|
+
.then((output) => {
|
|
88
|
+
if (!generator.onFinish) {
|
|
89
|
+
return output;
|
|
90
|
+
}
|
|
91
|
+
return generator.onFinish(output);
|
|
92
|
+
})
|
|
93
|
+
.then(callHook_1.default.bind(null, "finish", (output) => {
|
|
94
|
+
return {};
|
|
95
|
+
}, (output) => {
|
|
96
|
+
return output;
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Generate a book using a generator.
|
|
101
|
+
*
|
|
102
|
+
* The overall process is:
|
|
103
|
+
* 1. List and load plugins for this book
|
|
104
|
+
* 2. Call hook "config"
|
|
105
|
+
* 3. Call hook "init"
|
|
106
|
+
* 4. Initialize generator
|
|
107
|
+
* 5. List all assets and pages
|
|
108
|
+
* 6. Copy all assets to output
|
|
109
|
+
* 7. Generate all pages
|
|
110
|
+
* 8. Call hook "finish:before"
|
|
111
|
+
* 9. Finish generation
|
|
112
|
+
* 10. Call hook "finish"
|
|
113
|
+
*
|
|
114
|
+
*
|
|
115
|
+
* @param {Generator} generator
|
|
116
|
+
* @param {Book} book
|
|
117
|
+
* @param {Object} [options = {}]
|
|
118
|
+
* @return {Promise<Output>}
|
|
119
|
+
*/
|
|
120
|
+
function generateBook(generator, book, options = {}) {
|
|
121
|
+
options = generator.Options(options);
|
|
122
|
+
const state = generator.State ? new generator.State({}) : immutable_1.default.Map();
|
|
123
|
+
const start = Date.now();
|
|
124
|
+
return (promise_1.default(new output_1.default({
|
|
125
|
+
book: book,
|
|
126
|
+
options: options,
|
|
127
|
+
state: state,
|
|
128
|
+
generator: generator.name,
|
|
129
|
+
}))
|
|
130
|
+
// Cleanup output folder
|
|
131
|
+
.then((output) => {
|
|
132
|
+
const logger = output.getLogger();
|
|
133
|
+
const rootFolder = output.getRoot();
|
|
134
|
+
logger.debug.ln(`cleanup folder "${rootFolder}"`);
|
|
135
|
+
return fs_1.default.ensureFolder(rootFolder).thenResolve(output);
|
|
136
|
+
})
|
|
137
|
+
.then(processOutput.bind(null, generator))
|
|
138
|
+
// Log duration and end message
|
|
139
|
+
.then((output) => {
|
|
140
|
+
const logger = output.getLogger();
|
|
141
|
+
const end = Date.now();
|
|
142
|
+
const duration = (end - start) / 1000;
|
|
143
|
+
logger.info.ok(`generation finished with success in ${duration.toFixed(1)}s !`);
|
|
144
|
+
return output;
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
exports.generateBook = generateBook;
|
|
148
|
+
/**
|
|
149
|
+
* Incremental build for pages
|
|
150
|
+
* output should be prepared plugins
|
|
151
|
+
* @param generator
|
|
152
|
+
* @param output
|
|
153
|
+
* @returns {Promise<Promise<Output>>}
|
|
154
|
+
*/
|
|
155
|
+
function incrementalBuild(generator, output) {
|
|
156
|
+
const start = Date.now();
|
|
157
|
+
return generateAssets_1.default(generator, output)
|
|
158
|
+
.then((output) => generatePages_1.default(generator, output))
|
|
159
|
+
.then((output) => {
|
|
160
|
+
const logger = output.getLogger();
|
|
161
|
+
const end = Date.now();
|
|
162
|
+
const duration = (end - start) / 1000;
|
|
163
|
+
logger.info.ok(`generation finished with success in ${duration.toFixed(1)}s !`);
|
|
164
|
+
return output;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
exports.incrementalBuild = incrementalBuild;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const promise_1 = __importDefault(require("../utils/promise"));
|
|
8
|
+
const error_1 = __importDefault(require("../utils/error"));
|
|
9
|
+
const timing_1 = __importDefault(require("../utils/timing"));
|
|
10
|
+
const templating_1 = __importDefault(require("../templating"));
|
|
11
|
+
const json_1 = __importDefault(require("../json"));
|
|
12
|
+
const createTemplateEngine_1 = __importDefault(require("./createTemplateEngine"));
|
|
13
|
+
const callPageHook_1 = __importDefault(require("./callPageHook"));
|
|
14
|
+
const page_cache_1 = require("./page-cache");
|
|
15
|
+
const page_1 = __importDefault(require("../models/page"));
|
|
16
|
+
/**
|
|
17
|
+
* Prepare and generate HTML for a page
|
|
18
|
+
*
|
|
19
|
+
* @param {Output} output
|
|
20
|
+
* @param {Page} page
|
|
21
|
+
* @return {Promise<Page>}
|
|
22
|
+
*/
|
|
23
|
+
function generatePage(output, page) {
|
|
24
|
+
const book = output.getBook();
|
|
25
|
+
const engine = createTemplateEngine_1.default(output);
|
|
26
|
+
const cache = page_cache_1.getCache();
|
|
27
|
+
return timing_1.default.measure("page.generate", promise_1.default(page).then((resultPage) => {
|
|
28
|
+
const file = resultPage.getFile();
|
|
29
|
+
const filePath = file.getPath();
|
|
30
|
+
const parser = file.getParser();
|
|
31
|
+
const context = json_1.default.encodeOutputWithPage(output, resultPage);
|
|
32
|
+
if (!parser) {
|
|
33
|
+
return promise_1.default.reject(error_1.default.FileNotParsableError({
|
|
34
|
+
filename: filePath,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
// Call hook "page:before"
|
|
38
|
+
// const start = Date.now();
|
|
39
|
+
return (callPageHook_1.default("page:before", output, resultPage)
|
|
40
|
+
// Escape code blocks with raw tags
|
|
41
|
+
.then((currentPage) => {
|
|
42
|
+
// console.log("page:before", Date.now() - start);
|
|
43
|
+
return parser.preparePage(currentPage.getContent());
|
|
44
|
+
})
|
|
45
|
+
// Render templating syntax
|
|
46
|
+
.then(async (content) => {
|
|
47
|
+
// console.log("page:preparePage", Date.now() - start);
|
|
48
|
+
const absoluteFilePath = path_1.default.join(book.getContentRoot(), filePath);
|
|
49
|
+
// if has compiled pages, use it instead of compiling page
|
|
50
|
+
const pageHash = page.hash();
|
|
51
|
+
const cachedPage = cache.getKey(pageHash);
|
|
52
|
+
if (cachedPage) {
|
|
53
|
+
return page_1.default.fromJSON(output);
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const output = await templating_1.default.render(engine, absoluteFilePath, content, context);
|
|
57
|
+
// update cache
|
|
58
|
+
cache.setKey(pageHash, page_1.default.toJSON(output));
|
|
59
|
+
return output;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error("Template Rendering Error", error);
|
|
63
|
+
console.log("Template content", content);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
.then((output) => {
|
|
68
|
+
// console.log("page:render", Date.now() - start);
|
|
69
|
+
const content = output.getContent();
|
|
70
|
+
return parser.parsePage(content).then((result) => {
|
|
71
|
+
return output.setContent(result.content);
|
|
72
|
+
});
|
|
73
|
+
})
|
|
74
|
+
// Post processing for templating syntax
|
|
75
|
+
.then((output) => {
|
|
76
|
+
// console.log("page:parsePage", Date.now() - start);
|
|
77
|
+
return templating_1.default.postRender(engine, output);
|
|
78
|
+
})
|
|
79
|
+
// Return new page
|
|
80
|
+
.then((content) => {
|
|
81
|
+
// console.log("page:postRender", Date.now() - start);
|
|
82
|
+
return resultPage.set("content", content);
|
|
83
|
+
})
|
|
84
|
+
// Call final hook
|
|
85
|
+
.then((currentPage) => {
|
|
86
|
+
return callPageHook_1.default("page", output, currentPage);
|
|
87
|
+
}));
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
exports.default = generatePage;
|