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 object_path_1 = __importDefault(require("object-path"));
|
|
7
|
+
const deprecate_1 = __importDefault(require("./deprecate"));
|
|
8
|
+
/**
|
|
9
|
+
Encode a config object into a JS config api
|
|
10
|
+
|
|
11
|
+
@param {Output} output
|
|
12
|
+
@param {Config} config
|
|
13
|
+
@return {Object}
|
|
14
|
+
*/
|
|
15
|
+
function encodeConfig(output, config) {
|
|
16
|
+
const result = {
|
|
17
|
+
values: config.getValues().toJS(),
|
|
18
|
+
get: function (key, defaultValue) {
|
|
19
|
+
return object_path_1.default.get(result.values, key, defaultValue);
|
|
20
|
+
},
|
|
21
|
+
set: function (key, value) {
|
|
22
|
+
return object_path_1.default.set(result.values, key, value);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
deprecate_1.default.field(output, "config.options", result, "options", result.values, '"config.options" property is deprecated, use "config.get(key)" instead');
|
|
26
|
+
deprecate_1.default.field(output, "config.options.generator", result.values, "generator", output.getGenerator(), '"options.generator" property is deprecated, use "output.name" instead');
|
|
27
|
+
deprecate_1.default.field(output, "config.options.generator", result.values, "output", output.getRoot(), '"options.output" property is deprecated, use "output.root()" instead');
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
exports.default = encodeConfig;
|
|
@@ -0,0 +1,226 @@
|
|
|
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 path_2 = __importDefault(require("../utils/path"));
|
|
9
|
+
const fs_1 = __importDefault(require("../utils/fs"));
|
|
10
|
+
const plugins_1 = __importDefault(require("../plugins"));
|
|
11
|
+
const deprecate_1 = __importDefault(require("./deprecate"));
|
|
12
|
+
const fileToURL_1 = __importDefault(require("../output/helper/fileToURL"));
|
|
13
|
+
const defaultBlocks_1 = __importDefault(require("../constants/defaultBlocks"));
|
|
14
|
+
const honkit_1 = __importDefault(require("../honkit"));
|
|
15
|
+
const parsers_1 = __importDefault(require("../parsers"));
|
|
16
|
+
const encodeConfig_1 = __importDefault(require("./encodeConfig"));
|
|
17
|
+
const encodeSummary_1 = __importDefault(require("./encodeSummary"));
|
|
18
|
+
const encodeNavigation_1 = __importDefault(require("./encodeNavigation"));
|
|
19
|
+
const encodePage_1 = __importDefault(require("./encodePage"));
|
|
20
|
+
/**
|
|
21
|
+
Encode a global context into a JS object
|
|
22
|
+
It's the context for page's hook, etc
|
|
23
|
+
|
|
24
|
+
@param {Output} output
|
|
25
|
+
@return {Object}
|
|
26
|
+
*/
|
|
27
|
+
function encodeGlobal(output) {
|
|
28
|
+
const book = output.getBook();
|
|
29
|
+
const bookFS = book.getContentFS();
|
|
30
|
+
const logger = output.getLogger();
|
|
31
|
+
const outputFolder = output.getRoot();
|
|
32
|
+
const plugins = output.getPlugins();
|
|
33
|
+
const blocks = plugins_1.default.listBlocks(plugins);
|
|
34
|
+
const result = {
|
|
35
|
+
log: logger,
|
|
36
|
+
config: encodeConfig_1.default(output, book.getConfig()),
|
|
37
|
+
summary: encodeSummary_1.default(output, book.getSummary()),
|
|
38
|
+
/**
|
|
39
|
+
Check if the book is a multilingual book
|
|
40
|
+
|
|
41
|
+
@return {boolean}
|
|
42
|
+
*/
|
|
43
|
+
isMultilingual: function () {
|
|
44
|
+
return book.isMultilingual();
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
Check if the book is a language book for a multilingual book
|
|
48
|
+
|
|
49
|
+
@return {boolean}
|
|
50
|
+
*/
|
|
51
|
+
isLanguageBook: function () {
|
|
52
|
+
return book.isLanguageBook();
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
Read a file from the book
|
|
56
|
+
|
|
57
|
+
@param {string} fileName
|
|
58
|
+
@return {Promise<Buffer>}
|
|
59
|
+
*/
|
|
60
|
+
readFile: function (fileName) {
|
|
61
|
+
return bookFS.read(fileName);
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
Read a file from the book as a string
|
|
65
|
+
|
|
66
|
+
@param {string} fileName
|
|
67
|
+
@return {Promise<String>}
|
|
68
|
+
*/
|
|
69
|
+
readFileAsString: function (fileName) {
|
|
70
|
+
return bookFS.readAsString(fileName);
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
Resolve a file from the book root
|
|
74
|
+
|
|
75
|
+
@param {string} fileName
|
|
76
|
+
@return {string}
|
|
77
|
+
*/
|
|
78
|
+
resolve: function (fileName) {
|
|
79
|
+
return path_1.default.resolve(book.getContentRoot(), fileName);
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
Resolve a page by it path
|
|
83
|
+
|
|
84
|
+
@param {string} filePath
|
|
85
|
+
@return {string}
|
|
86
|
+
*/
|
|
87
|
+
getPageByPath: function (filePath) {
|
|
88
|
+
const page = output.getPage(filePath);
|
|
89
|
+
if (!page)
|
|
90
|
+
return undefined;
|
|
91
|
+
return encodePage_1.default(output, page);
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
Render a block of text (markdown/asciidoc)
|
|
95
|
+
|
|
96
|
+
@param {string} type
|
|
97
|
+
@param {string} text
|
|
98
|
+
@return {Promise<String>}
|
|
99
|
+
*/
|
|
100
|
+
renderBlock: function (type, text) {
|
|
101
|
+
const parser = parsers_1.default.get(type);
|
|
102
|
+
return parser.parsePage(text).get("content");
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
Render an inline text (markdown/asciidoc)
|
|
106
|
+
|
|
107
|
+
@param {string} type
|
|
108
|
+
@param {string} text
|
|
109
|
+
@return {Promise<String>}
|
|
110
|
+
*/
|
|
111
|
+
renderInline: function (type, text) {
|
|
112
|
+
const parser = parsers_1.default.get(type);
|
|
113
|
+
return parser.parseInline(text).get("content");
|
|
114
|
+
},
|
|
115
|
+
template: {
|
|
116
|
+
/**
|
|
117
|
+
Apply a templating block and returns its result
|
|
118
|
+
|
|
119
|
+
@param {string} name
|
|
120
|
+
@param {Object} blockData
|
|
121
|
+
@return {Promise|Object}
|
|
122
|
+
*/
|
|
123
|
+
applyBlock: function (name, blockData) {
|
|
124
|
+
const block = blocks.get(name) || defaultBlocks_1.default.get(name);
|
|
125
|
+
return promise_1.default(block.applyBlock(blockData, result));
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
output: {
|
|
129
|
+
/**
|
|
130
|
+
Name of the generator being used
|
|
131
|
+
{string}
|
|
132
|
+
*/
|
|
133
|
+
name: output.getGenerator(),
|
|
134
|
+
/**
|
|
135
|
+
Return absolute path to the root folder of output
|
|
136
|
+
@return {string}
|
|
137
|
+
*/
|
|
138
|
+
root: function () {
|
|
139
|
+
return outputFolder;
|
|
140
|
+
},
|
|
141
|
+
/**
|
|
142
|
+
Resolve a file from the output root
|
|
143
|
+
|
|
144
|
+
@param {string} fileName
|
|
145
|
+
@return {string}
|
|
146
|
+
*/
|
|
147
|
+
resolve: function (fileName) {
|
|
148
|
+
return path_1.default.resolve(outputFolder, fileName);
|
|
149
|
+
},
|
|
150
|
+
/**
|
|
151
|
+
Convert a filepath into an url
|
|
152
|
+
@return {string}
|
|
153
|
+
*/
|
|
154
|
+
toURL: function (filePath) {
|
|
155
|
+
return fileToURL_1.default(output, filePath);
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
Check that a file exists.
|
|
159
|
+
|
|
160
|
+
@param {string} fileName
|
|
161
|
+
@return {Promise}
|
|
162
|
+
*/
|
|
163
|
+
hasFile: function (fileName, content) {
|
|
164
|
+
return promise_1.default().then(() => {
|
|
165
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 2.
|
|
166
|
+
const filePath = path_2.default.resolveInRoot(outputFolder, fileName);
|
|
167
|
+
return fs_1.default.exists(filePath);
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
/**
|
|
171
|
+
Write a file to the output folder,
|
|
172
|
+
It creates the required folder
|
|
173
|
+
|
|
174
|
+
@param {string} fileName
|
|
175
|
+
@param {Buffer} content
|
|
176
|
+
@return {Promise}
|
|
177
|
+
*/
|
|
178
|
+
writeFile: function (fileName, content) {
|
|
179
|
+
return promise_1.default().then(() => {
|
|
180
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 2.
|
|
181
|
+
const filePath = path_2.default.resolveInRoot(outputFolder, fileName);
|
|
182
|
+
return fs_1.default.ensureFile(filePath).then(() => {
|
|
183
|
+
return fs_1.default.writeFile(filePath, content);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
/**
|
|
188
|
+
Copy a file to the output folder
|
|
189
|
+
It creates the required folder.
|
|
190
|
+
|
|
191
|
+
@param {string} inputFile
|
|
192
|
+
@param {string} outputFile
|
|
193
|
+
@param {Buffer} content
|
|
194
|
+
@return {Promise}
|
|
195
|
+
*/
|
|
196
|
+
copyFile: function (inputFile, outputFile, content) {
|
|
197
|
+
return promise_1.default().then(() => {
|
|
198
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 2.
|
|
199
|
+
const outputFilePath = path_2.default.resolveInRoot(outputFolder, outputFile);
|
|
200
|
+
return fs_1.default.ensureFile(outputFilePath).then(() => {
|
|
201
|
+
return fs_1.default.copy(inputFile, outputFilePath);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
gitbook: {
|
|
207
|
+
version: honkit_1.default.version,
|
|
208
|
+
},
|
|
209
|
+
honkit: {
|
|
210
|
+
version: honkit_1.default.version,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
// Deprecated properties
|
|
214
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 6 arguments, but got 5.
|
|
215
|
+
deprecate_1.default.renamedMethod(output, "this.isSubBook", result, "isSubBook", "isLanguageBook");
|
|
216
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 6 arguments, but got 5.
|
|
217
|
+
deprecate_1.default.renamedMethod(output, "this.contentLink", result, "contentLink", "output.toURL");
|
|
218
|
+
deprecate_1.default.field(output, "this.generator", result, "generator", output.getGenerator(), '"this.generator" property is deprecated, use "this.output.name" instead');
|
|
219
|
+
deprecate_1.default.field(output, "this.navigation", result, "navigation", () => {
|
|
220
|
+
return encodeNavigation_1.default(output);
|
|
221
|
+
}, '"navigation" property is deprecated');
|
|
222
|
+
deprecate_1.default.field(output, "this.book", result, "book", result, '"book" property is deprecated, use "this" directly instead');
|
|
223
|
+
deprecate_1.default.field(output, "this.options", result, "options", result.config.values, '"options" property is deprecated, use config.get(key) instead');
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
exports.default = encodeGlobal;
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
/**
|
|
8
|
+
Encode an article for next/prev
|
|
9
|
+
|
|
10
|
+
@param {Map<String:Page>}
|
|
11
|
+
@param {Article}
|
|
12
|
+
@return {Object}
|
|
13
|
+
*/
|
|
14
|
+
function encodeArticle(pages, article) {
|
|
15
|
+
const articlePath = article.getPath();
|
|
16
|
+
return {
|
|
17
|
+
path: articlePath,
|
|
18
|
+
title: article.getTitle(),
|
|
19
|
+
level: article.getLevel(),
|
|
20
|
+
exists: articlePath && pages.has(articlePath),
|
|
21
|
+
external: article.isExternal(),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
this.navigation is a deprecated property from GitBook v2
|
|
26
|
+
|
|
27
|
+
@param {Output}
|
|
28
|
+
@return {Object}
|
|
29
|
+
*/
|
|
30
|
+
function encodeNavigation(output) {
|
|
31
|
+
const book = output.getBook();
|
|
32
|
+
const pages = output.getPages();
|
|
33
|
+
const summary = book.getSummary();
|
|
34
|
+
const articles = summary.getArticlesAsList();
|
|
35
|
+
const navigation = articles
|
|
36
|
+
.map((article, i) => {
|
|
37
|
+
const ref = article.getRef();
|
|
38
|
+
if (!ref) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const prev = articles.get(i - 1);
|
|
42
|
+
const next = articles.get(i + 1);
|
|
43
|
+
return [
|
|
44
|
+
ref,
|
|
45
|
+
{
|
|
46
|
+
index: i,
|
|
47
|
+
title: article.getTitle(),
|
|
48
|
+
introduction: i === 0,
|
|
49
|
+
prev: prev ? encodeArticle(pages, prev) : undefined,
|
|
50
|
+
next: next ? encodeArticle(pages, next) : undefined,
|
|
51
|
+
level: article.getLevel(),
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
})
|
|
55
|
+
.filter((e) => {
|
|
56
|
+
return Boolean(e);
|
|
57
|
+
});
|
|
58
|
+
return immutable_1.default.Map(navigation).toJS();
|
|
59
|
+
}
|
|
60
|
+
exports.default = encodeNavigation;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 json_1 = __importDefault(require("../json"));
|
|
7
|
+
const deprecate_1 = __importDefault(require("./deprecate"));
|
|
8
|
+
const encodeProgress_1 = __importDefault(require("./encodeProgress"));
|
|
9
|
+
/**
|
|
10
|
+
Encode a page in a context to a JS API
|
|
11
|
+
|
|
12
|
+
@param {Output} output
|
|
13
|
+
@param {Page} page
|
|
14
|
+
@return {Object}
|
|
15
|
+
*/
|
|
16
|
+
function encodePage(output, page) {
|
|
17
|
+
const book = output.getBook();
|
|
18
|
+
const summary = book.getSummary();
|
|
19
|
+
const fs = book.getContentFS();
|
|
20
|
+
const file = page.getFile();
|
|
21
|
+
// JS Page is based on the JSON output
|
|
22
|
+
const result = json_1.default.encodePage(page, summary);
|
|
23
|
+
result.type = file.getType();
|
|
24
|
+
result.path = file.getPath();
|
|
25
|
+
result.rawPath = fs.resolve(result.path);
|
|
26
|
+
deprecate_1.default.field(output, "page.progress", result, "progress", () => {
|
|
27
|
+
return encodeProgress_1.default(output, page);
|
|
28
|
+
}, '"page.progress" property is deprecated');
|
|
29
|
+
deprecate_1.default.field(output, "page.sections", result, "sections", [
|
|
30
|
+
{
|
|
31
|
+
content: result.content,
|
|
32
|
+
type: "normal",
|
|
33
|
+
},
|
|
34
|
+
], '"sections" property is deprecated, use page.content instead');
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
exports.default = encodePage;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 encodeNavigation_1 = __importDefault(require("./encodeNavigation"));
|
|
8
|
+
/**
|
|
9
|
+
page.progress is a deprecated property from GitBook v2
|
|
10
|
+
|
|
11
|
+
@param {Output}
|
|
12
|
+
@param {Page}
|
|
13
|
+
@return {Object}
|
|
14
|
+
*/
|
|
15
|
+
function encodeProgress(output, page) {
|
|
16
|
+
const current = page.getPath();
|
|
17
|
+
let navigation = encodeNavigation_1.default(output);
|
|
18
|
+
navigation = immutable_1.default.Map(navigation);
|
|
19
|
+
const n = navigation.size;
|
|
20
|
+
let percent = 0, prevPercent = 0, currentChapter = null;
|
|
21
|
+
let done = true;
|
|
22
|
+
const chapters = navigation
|
|
23
|
+
.map((nav, chapterPath) => {
|
|
24
|
+
nav.path = chapterPath;
|
|
25
|
+
return nav;
|
|
26
|
+
})
|
|
27
|
+
.valueSeq()
|
|
28
|
+
.sortBy((nav) => {
|
|
29
|
+
return nav.index;
|
|
30
|
+
})
|
|
31
|
+
.map((nav, i) => {
|
|
32
|
+
// Calcul percent
|
|
33
|
+
nav.percent = (i * 100) / Math.max(n - 1, 1);
|
|
34
|
+
// Is it done
|
|
35
|
+
nav.done = done;
|
|
36
|
+
if (nav.path == current) {
|
|
37
|
+
currentChapter = nav;
|
|
38
|
+
percent = nav.percent;
|
|
39
|
+
done = false;
|
|
40
|
+
}
|
|
41
|
+
else if (done) {
|
|
42
|
+
prevPercent = nav.percent;
|
|
43
|
+
}
|
|
44
|
+
return nav;
|
|
45
|
+
})
|
|
46
|
+
.toJS();
|
|
47
|
+
return {
|
|
48
|
+
// Previous percent
|
|
49
|
+
prevPercent: prevPercent,
|
|
50
|
+
// Current percent
|
|
51
|
+
percent: percent,
|
|
52
|
+
// List of chapter with progress
|
|
53
|
+
chapters: chapters,
|
|
54
|
+
// Current chapter
|
|
55
|
+
current: currentChapter,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.default = encodeProgress;
|
|
@@ -0,0 +1,52 @@
|
|
|
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 encodeSummaryArticle_1 = __importDefault(require("../json/encodeSummaryArticle"));
|
|
7
|
+
/**
|
|
8
|
+
Encode summary to provide an API to plugin
|
|
9
|
+
|
|
10
|
+
@param {Output} output
|
|
11
|
+
@param {Config} config
|
|
12
|
+
@return {Object}
|
|
13
|
+
*/
|
|
14
|
+
function encodeSummary(output, summary) {
|
|
15
|
+
const result = {
|
|
16
|
+
/**
|
|
17
|
+
Iterate over the summary, it stops when the "iter" returns false
|
|
18
|
+
|
|
19
|
+
@param {Function} iter
|
|
20
|
+
*/
|
|
21
|
+
walk: function (iter) {
|
|
22
|
+
summary.getArticle((article) => {
|
|
23
|
+
const jsonArticle = encodeSummaryArticle_1.default(article, false);
|
|
24
|
+
return iter(jsonArticle);
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
Get an article by its level
|
|
29
|
+
|
|
30
|
+
@param {string} level
|
|
31
|
+
@return {Object}
|
|
32
|
+
*/
|
|
33
|
+
getArticleByLevel: function (level) {
|
|
34
|
+
const article = summary.getByLevel(level);
|
|
35
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
|
36
|
+
return article ? encodeSummaryArticle_1.default(article) : undefined;
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
Get an article by its path
|
|
40
|
+
|
|
41
|
+
@param {string} level
|
|
42
|
+
@return {Object}
|
|
43
|
+
*/
|
|
44
|
+
getArticleByPath: function (level) {
|
|
45
|
+
const article = summary.getByPath(level);
|
|
46
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
|
47
|
+
return article ? encodeSummaryArticle_1.default(article) : undefined;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
exports.default = encodeSummary;
|