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,55 @@
|
|
|
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.generateMockBook = void 0;
|
|
7
|
+
const mock_1 = __importDefault(require("../../fs/mock"));
|
|
8
|
+
const tmp_1 = __importDefault(require("tmp"));
|
|
9
|
+
const book_1 = __importDefault(require("../../models/book"));
|
|
10
|
+
const parseBook_1 = __importDefault(require("../../parse/parseBook"));
|
|
11
|
+
const generateBook_1 = require("../generateBook");
|
|
12
|
+
/**
|
|
13
|
+
* Generate a book using a generator
|
|
14
|
+
* And returns the path to the output dir.
|
|
15
|
+
*
|
|
16
|
+
* FOR TESTING PURPOSE ONLY
|
|
17
|
+
*
|
|
18
|
+
* @param Generator
|
|
19
|
+
* @param {Map<String:String|Map>} files
|
|
20
|
+
* @return {Promise<String>}
|
|
21
|
+
*/
|
|
22
|
+
function generateMockBook(Generator, files) {
|
|
23
|
+
const fs = mock_1.default(files);
|
|
24
|
+
let book = book_1.default.createForFS(fs);
|
|
25
|
+
const dir = tmp_1.default.dirSync();
|
|
26
|
+
book = book.setLogLevel("disabled");
|
|
27
|
+
return parseBook_1.default(book)
|
|
28
|
+
.then((resultBook) => {
|
|
29
|
+
return generateBook_1.generateBook(Generator, resultBook, {
|
|
30
|
+
root: dir.name,
|
|
31
|
+
});
|
|
32
|
+
})
|
|
33
|
+
.then((output) => {
|
|
34
|
+
return {
|
|
35
|
+
book,
|
|
36
|
+
output,
|
|
37
|
+
dir: dir.name,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.generateMockBook = generateMockBook;
|
|
42
|
+
/**
|
|
43
|
+
* Generate a book using a generator
|
|
44
|
+
* And returns the path to the output dir.
|
|
45
|
+
*
|
|
46
|
+
* FOR TESTING PURPOSE ONLY
|
|
47
|
+
*
|
|
48
|
+
* @param Generator
|
|
49
|
+
* @param {Map<String:String|Map>} files
|
|
50
|
+
* @return {Promise<String>}
|
|
51
|
+
*/
|
|
52
|
+
function generateMock(Generator, files) {
|
|
53
|
+
return generateMockBook(Generator, files).then((ret) => ret.dir);
|
|
54
|
+
}
|
|
55
|
+
exports.default = generateMock;
|
|
@@ -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 createTemplateEngine_1 = __importDefault(require("../createTemplateEngine"));
|
|
7
|
+
const createMock_1 = __importDefault(require("../../testing/createMock"));
|
|
8
|
+
const prepareI18n_1 = __importDefault(require("../prepareI18n"));
|
|
9
|
+
const __1 = __importDefault(require("../"));
|
|
10
|
+
describe("i18n", () => {
|
|
11
|
+
test("should correctly use english as default language", () => {
|
|
12
|
+
// @ts-expect-error
|
|
13
|
+
return createMock_1.default(__1.default, {
|
|
14
|
+
"README.md": "Hello World"
|
|
15
|
+
})
|
|
16
|
+
.then((output) => {
|
|
17
|
+
return prepareI18n_1.default(output);
|
|
18
|
+
})
|
|
19
|
+
.then((output) => {
|
|
20
|
+
const engine = createTemplateEngine_1.default(output, "README.md");
|
|
21
|
+
const t = engine.getFilters().get("t");
|
|
22
|
+
expect(t("SUMMARY_INTRODUCTION")).toEqual("Introduction");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
test("should correctly use language from book.json", () => {
|
|
26
|
+
// @ts-expect-error
|
|
27
|
+
return createMock_1.default(__1.default, {
|
|
28
|
+
"README.md": "Hello World",
|
|
29
|
+
"book.json": JSON.stringify({ language: "fr" })
|
|
30
|
+
})
|
|
31
|
+
.then((output) => {
|
|
32
|
+
return prepareI18n_1.default(output);
|
|
33
|
+
})
|
|
34
|
+
.then((output) => {
|
|
35
|
+
const engine = createTemplateEngine_1.default(output, "README.md");
|
|
36
|
+
const t = engine.getFilters().get("t");
|
|
37
|
+
expect(t("GITBOOK_LINK")).toEqual("Publié avec HonKit");
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
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 pluginAssetsFolder_1 = __importDefault(require("../../constants/pluginAssetsFolder"));
|
|
8
|
+
const promise_1 = __importDefault(require("../../utils/promise"));
|
|
9
|
+
const fs_1 = __importDefault(require("../../utils/fs"));
|
|
10
|
+
/**
|
|
11
|
+
Copy all assets from plugins.
|
|
12
|
+
Assets are files stored in "_assets"
|
|
13
|
+
nd resources declared in the plugin itself.
|
|
14
|
+
|
|
15
|
+
@param {Output}
|
|
16
|
+
@return {Promise}
|
|
17
|
+
*/
|
|
18
|
+
function copyPluginAssets(output) {
|
|
19
|
+
const book = output.getBook();
|
|
20
|
+
// Don't copy plugins assets for language book
|
|
21
|
+
// It'll be resolved to the parent folder
|
|
22
|
+
if (book.isLanguageBook()) {
|
|
23
|
+
return promise_1.default(output);
|
|
24
|
+
}
|
|
25
|
+
const plugins = output
|
|
26
|
+
.getPlugins()
|
|
27
|
+
// We reverse the order of plugins to copy
|
|
28
|
+
// so that first plugins can replace assets from other plugins.
|
|
29
|
+
.reverse();
|
|
30
|
+
return promise_1.default.forEach(plugins, (plugin) => {
|
|
31
|
+
return copyAssets(output, plugin).then(() => {
|
|
32
|
+
return copyResources(output, plugin);
|
|
33
|
+
});
|
|
34
|
+
}).thenResolve(output);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
Copy assets from a plugin
|
|
38
|
+
|
|
39
|
+
@param {Plugin}
|
|
40
|
+
@return {Promise}
|
|
41
|
+
*/
|
|
42
|
+
function copyAssets(output, plugin) {
|
|
43
|
+
const logger = output.getLogger();
|
|
44
|
+
const pluginRoot = plugin.getPath();
|
|
45
|
+
const options = output.getOptions();
|
|
46
|
+
const outputRoot = options.get("root");
|
|
47
|
+
const assetOutputFolder = path_1.default.join(outputRoot, "gitbook");
|
|
48
|
+
const prefix = options.get("prefix");
|
|
49
|
+
const assetFolder = path_1.default.join(pluginRoot, pluginAssetsFolder_1.default, prefix);
|
|
50
|
+
if (!fs_1.default.existsSync(assetFolder)) {
|
|
51
|
+
return promise_1.default();
|
|
52
|
+
}
|
|
53
|
+
logger.debug.ln("copy assets from theme", assetFolder);
|
|
54
|
+
return fs_1.default.copyDir(assetFolder, assetOutputFolder, {
|
|
55
|
+
deleteFirst: false,
|
|
56
|
+
overwrite: true,
|
|
57
|
+
confirm: false,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
Copy resources from a plugin
|
|
62
|
+
|
|
63
|
+
@param {Plugin}
|
|
64
|
+
@return {Promise}
|
|
65
|
+
*/
|
|
66
|
+
function copyResources(output, plugin) {
|
|
67
|
+
const logger = output.getLogger();
|
|
68
|
+
const options = output.getOptions();
|
|
69
|
+
const outputRoot = options.get("root");
|
|
70
|
+
const state = output.getState();
|
|
71
|
+
const resources = state.getResources();
|
|
72
|
+
const pluginRoot = plugin.getPath();
|
|
73
|
+
const pluginResources = resources.get(plugin.getName());
|
|
74
|
+
let assetsFolder = pluginResources.get("assets");
|
|
75
|
+
const assetOutputFolder = path_1.default.join(outputRoot, "gitbook", plugin.getNpmID());
|
|
76
|
+
if (!assetsFolder) {
|
|
77
|
+
return promise_1.default();
|
|
78
|
+
}
|
|
79
|
+
// Resolve assets folder
|
|
80
|
+
assetsFolder = path_1.default.resolve(pluginRoot, assetsFolder);
|
|
81
|
+
if (!fs_1.default.existsSync(assetsFolder)) {
|
|
82
|
+
logger.warn.ln(`assets folder for plugin "${plugin.getName()}" doesn't exist`);
|
|
83
|
+
return promise_1.default();
|
|
84
|
+
}
|
|
85
|
+
logger.debug.ln("copy resources from plugin", assetsFolder);
|
|
86
|
+
return fs_1.default.copyDir(assetsFolder, assetOutputFolder, {
|
|
87
|
+
deleteFirst: false,
|
|
88
|
+
overwrite: true,
|
|
89
|
+
confirm: false,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
exports.default = copyPluginAssets;
|
|
@@ -0,0 +1,136 @@
|
|
|
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 nunjucks_1 = __importDefault(require("nunjucks"));
|
|
8
|
+
const nunjucks_do_1 = __importDefault(require("nunjucks-do"));
|
|
9
|
+
const DoExtension = nunjucks_do_1.default(nunjucks_1.default);
|
|
10
|
+
const memoize_one_1 = __importDefault(require("memoize-one"));
|
|
11
|
+
const api_1 = __importDefault(require("../../api"));
|
|
12
|
+
const deprecate_1 = __importDefault(require("../../api/deprecate"));
|
|
13
|
+
const json_1 = __importDefault(require("../../json"));
|
|
14
|
+
const location_1 = __importDefault(require("../../utils/location"));
|
|
15
|
+
const fs_1 = __importDefault(require("../../utils/fs"));
|
|
16
|
+
const path_2 = __importDefault(require("../../utils/path"));
|
|
17
|
+
const templateEngine_1 = __importDefault(require("../../models/templateEngine"));
|
|
18
|
+
const templatesFolder_1 = __importDefault(require("../../constants/templatesFolder"));
|
|
19
|
+
const defaultFilters_1 = __importDefault(require("../../constants/defaultFilters"));
|
|
20
|
+
const templating_1 = __importDefault(require("../../templating"));
|
|
21
|
+
const listSearchPaths_1 = __importDefault(require("./listSearchPaths"));
|
|
22
|
+
const fileToURL_1 = __importDefault(require("../helper/fileToURL"));
|
|
23
|
+
const resolveFileToURL_1 = __importDefault(require("../helper/resolveFileToURL"));
|
|
24
|
+
/**
|
|
25
|
+
* Directory for a theme with the templates
|
|
26
|
+
*/
|
|
27
|
+
function templateFolder(dir) {
|
|
28
|
+
return path_1.default.join(dir, templatesFolder_1.default);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create templating engine to render themes
|
|
32
|
+
*
|
|
33
|
+
* @param {Output} output
|
|
34
|
+
* @param {string} currentFile
|
|
35
|
+
* @return {TemplateEngine}
|
|
36
|
+
*/
|
|
37
|
+
function createTemplateEngine(output, currentFile) {
|
|
38
|
+
const book = output.getBook();
|
|
39
|
+
const state = output.getState();
|
|
40
|
+
// @ts-expect-error: state type
|
|
41
|
+
const i18n = state.getI18n();
|
|
42
|
+
const config = book.getConfig();
|
|
43
|
+
const summary = book.getSummary();
|
|
44
|
+
const outputFolder = output.getRoot();
|
|
45
|
+
// Search paths for templates
|
|
46
|
+
const searchPaths = listSearchPaths_1.default(output);
|
|
47
|
+
const tplSearchPaths = searchPaths.map(templateFolder);
|
|
48
|
+
// Create loader
|
|
49
|
+
// @ts-expect-error: Expected 0 arguments, but got 1.
|
|
50
|
+
const loader = new templating_1.default.ThemesLoader(tplSearchPaths);
|
|
51
|
+
// Get languages
|
|
52
|
+
const language = config.getValue("language");
|
|
53
|
+
// Create API context
|
|
54
|
+
const context = api_1.default.encodeGlobal(output);
|
|
55
|
+
/**
|
|
56
|
+
* Check if a file exists
|
|
57
|
+
* @param {string} fileName
|
|
58
|
+
* @return {boolean}
|
|
59
|
+
*/
|
|
60
|
+
function fileExists(fileName) {
|
|
61
|
+
if (!fileName) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 2.
|
|
65
|
+
const filePath = path_2.default.resolveInRoot(outputFolder, fileName);
|
|
66
|
+
return fs_1.default.existsSync(filePath);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Return an article by its path
|
|
70
|
+
* @param {string} filePath
|
|
71
|
+
* @return {Object|undefined}
|
|
72
|
+
*/
|
|
73
|
+
function getArticleByPath(filePath) {
|
|
74
|
+
const article = summary.getByPath(filePath);
|
|
75
|
+
if (!article)
|
|
76
|
+
return undefined;
|
|
77
|
+
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
|
78
|
+
return json_1.default.encodeSummaryArticle(article);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Return a page by its path
|
|
82
|
+
* @param {string} filePath
|
|
83
|
+
* @return {Object|undefined}
|
|
84
|
+
*/
|
|
85
|
+
function getPageByPath(filePath) {
|
|
86
|
+
const page = output.getPage(filePath);
|
|
87
|
+
if (!page)
|
|
88
|
+
return undefined;
|
|
89
|
+
return json_1.default.encodePage(page, summary);
|
|
90
|
+
}
|
|
91
|
+
return templateEngine_1.default.create({
|
|
92
|
+
loader: loader,
|
|
93
|
+
context: context,
|
|
94
|
+
globals: {
|
|
95
|
+
getArticleByPath: memoize_one_1.default(getArticleByPath),
|
|
96
|
+
getPageByPath: memoize_one_1.default(getPageByPath),
|
|
97
|
+
fileExists: fileExists,
|
|
98
|
+
},
|
|
99
|
+
filters: defaultFilters_1.default.merge({
|
|
100
|
+
/**
|
|
101
|
+
* Translate a sentence
|
|
102
|
+
*/
|
|
103
|
+
t: function t(s) {
|
|
104
|
+
return i18n.t(language, s);
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* Resolve an absolute file path into a
|
|
108
|
+
* relative path.
|
|
109
|
+
* it also resolve pages
|
|
110
|
+
*/
|
|
111
|
+
resolveFile: function (filePath) {
|
|
112
|
+
filePath = resolveFileToURL_1.default(output, filePath);
|
|
113
|
+
return location_1.default.relativeForFile(currentFile, filePath);
|
|
114
|
+
},
|
|
115
|
+
resolveAsset: function (filePath) {
|
|
116
|
+
filePath = location_1.default.toAbsolute(filePath, "", "");
|
|
117
|
+
filePath = path_1.default.join("gitbook", filePath);
|
|
118
|
+
filePath = location_1.default.relativeForFile(currentFile, filePath);
|
|
119
|
+
// Use assets from parent if language book
|
|
120
|
+
if (book.isLanguageBook()) {
|
|
121
|
+
filePath = path_1.default.join("../", filePath);
|
|
122
|
+
}
|
|
123
|
+
return location_1.default.normalize(filePath);
|
|
124
|
+
},
|
|
125
|
+
fileExists: deprecate_1.default.method(book, "fileExists", fileExists, 'Filter "fileExists" is deprecated, use "fileExists(filename)" '),
|
|
126
|
+
getArticleByPath: deprecate_1.default.method(book, "getArticleByPath", fileExists, 'Filter "getArticleByPath" is deprecated, use "getArticleByPath(filename)" '),
|
|
127
|
+
contentURL: function (filePath) {
|
|
128
|
+
return fileToURL_1.default(output, filePath);
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
extensions: {
|
|
132
|
+
DoExtension: new DoExtension(),
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
exports.default = createTemplateEngine;
|
|
@@ -0,0 +1,22 @@
|
|
|
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 onPage_1 = require("./onPage");
|
|
7
|
+
const onFinish_1 = require("./onFinish");
|
|
8
|
+
const state_1 = __importDefault(require("./state"));
|
|
9
|
+
const options_1 = __importDefault(require("./options"));
|
|
10
|
+
const onInit_1 = __importDefault(require("./onInit"));
|
|
11
|
+
const onAsset_1 = __importDefault(require("./onAsset"));
|
|
12
|
+
const createTemplateEngine_1 = __importDefault(require("./createTemplateEngine"));
|
|
13
|
+
exports.default = {
|
|
14
|
+
name: "website",
|
|
15
|
+
State: state_1.default,
|
|
16
|
+
Options: options_1.default,
|
|
17
|
+
onInit: onInit_1.default,
|
|
18
|
+
onFinish: onFinish_1.onFinish,
|
|
19
|
+
onPage: onPage_1.onPage,
|
|
20
|
+
onAsset: onAsset_1.default,
|
|
21
|
+
createTemplateEngine: createTemplateEngine_1.default,
|
|
22
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
List search paths for templates / i18n, etc
|
|
4
|
+
|
|
5
|
+
@param {Output} output
|
|
6
|
+
@return {List<String>}
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
function listSearchPaths(output) {
|
|
10
|
+
const book = output.getBook();
|
|
11
|
+
const plugins = output.getPlugins();
|
|
12
|
+
const searchPaths = plugins
|
|
13
|
+
.valueSeq()
|
|
14
|
+
.map((plugin) => {
|
|
15
|
+
return plugin.getPath();
|
|
16
|
+
})
|
|
17
|
+
.toList();
|
|
18
|
+
return searchPaths.unshift(book.getContentRoot());
|
|
19
|
+
}
|
|
20
|
+
exports.default = listSearchPaths;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
Copy an asset to the output folder
|
|
10
|
+
|
|
11
|
+
@param {Output} output
|
|
12
|
+
@param {Page} page
|
|
13
|
+
*/
|
|
14
|
+
function onAsset(output, asset) {
|
|
15
|
+
const book = output.getBook();
|
|
16
|
+
const options = output.getOptions();
|
|
17
|
+
const bookFS = book.getContentFS();
|
|
18
|
+
const outputFolder = options.get("root");
|
|
19
|
+
const outputPath = path_1.default.resolve(outputFolder, asset);
|
|
20
|
+
return fs_1.default
|
|
21
|
+
.ensureFile(outputPath)
|
|
22
|
+
.then(() => {
|
|
23
|
+
return bookFS.readAsStream(asset).then((stream) => {
|
|
24
|
+
return fs_1.default.writeStream(outputPath, stream);
|
|
25
|
+
});
|
|
26
|
+
})
|
|
27
|
+
.thenResolve(output);
|
|
28
|
+
}
|
|
29
|
+
exports.default = onAsset;
|
|
@@ -0,0 +1,35 @@
|
|
|
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.onFinish = void 0;
|
|
7
|
+
const promise_1 = __importDefault(require("../../utils/promise"));
|
|
8
|
+
const json_1 = __importDefault(require("../../json"));
|
|
9
|
+
const templating_1 = __importDefault(require("../../templating"));
|
|
10
|
+
const writeFile_1 = __importDefault(require("../helper/writeFile"));
|
|
11
|
+
const createTemplateEngine_1 = __importDefault(require("./createTemplateEngine"));
|
|
12
|
+
/**
|
|
13
|
+
Finish the generation, write the languages index
|
|
14
|
+
|
|
15
|
+
@param {Output} output
|
|
16
|
+
@return {Output}
|
|
17
|
+
*/
|
|
18
|
+
function onFinish(output) {
|
|
19
|
+
const book = output.getBook();
|
|
20
|
+
const options = output.getOptions();
|
|
21
|
+
const prefix = options.get("prefix");
|
|
22
|
+
if (!book.isMultilingual()) {
|
|
23
|
+
return promise_1.default(output);
|
|
24
|
+
}
|
|
25
|
+
const filePath = "index.html";
|
|
26
|
+
const engine = createTemplateEngine_1.default(output, filePath);
|
|
27
|
+
const context = json_1.default.encodeOutput(output);
|
|
28
|
+
// Render the theme
|
|
29
|
+
return (templating_1.default.renderFile(engine, `${prefix}/languages.html`, context)
|
|
30
|
+
// Write it to the disk
|
|
31
|
+
.then((tplOut) => {
|
|
32
|
+
return writeFile_1.default(output, filePath, tplOut.getContent());
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
exports.onFinish = onFinish;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
const copyPluginAssets_1 = __importDefault(require("./copyPluginAssets"));
|
|
8
|
+
const prepareI18n_1 = __importDefault(require("./prepareI18n"));
|
|
9
|
+
const prepareResources_1 = __importDefault(require("./prepareResources"));
|
|
10
|
+
/**
|
|
11
|
+
Initialize the generator
|
|
12
|
+
|
|
13
|
+
@param {Output}
|
|
14
|
+
@return {Output}
|
|
15
|
+
*/
|
|
16
|
+
function onInit(output) {
|
|
17
|
+
return promise_1.default(output).then(prepareI18n_1.default).then(prepareResources_1.default).then(copyPluginAssets_1.default);
|
|
18
|
+
}
|
|
19
|
+
exports.default = onInit;
|