docgen-tool 3.4.0 → 3.5.0
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/dist/include/templates/main.html +2 -43
- package/dist/include/templates/pdfCover.html +2 -50
- package/dist/include/templates/pdfFooter.html +1 -14
- package/dist/include/templates/webCover.html +0 -30
- package/dist/package.json +6 -4
- package/dist/src/docgen/docgen.js +36 -61
- package/dist/src/docgen/fs/fs.js +9 -9
- package/dist/src/docgen/fs/markdown.js +11 -11
- package/dist/src/docgen/fs/meta.js +10 -7
- package/dist/src/docgen/fs/templates.js +6 -6
- package/dist/src/docgen/fs/write-pages.js +45 -34
- package/dist/src/docgen/meta/derive-parameters.js +29 -0
- package/dist/src/docgen/meta/sort-pages.js +26 -9
- package/dist/src/docgen/pdf/wkhtmltopdf/wkhtmltopdf.js +16 -16
- package/dist/src/docgen/scaffold/scaffold.js +2 -2
- package/dist/src/docgen/validation/validation.js +4 -3
- package/dist/src/docgen/views/components/copyright/copyright.js +17 -0
- package/dist/src/docgen/views/components/footer/footer.js +22 -0
- package/dist/src/docgen/views/components/pdf-footer/pdf-footer.js +30 -0
- package/dist/src/docgen/views/components/web-table-of-contents/web-table-of-contents.js +41 -0
- package/dist/src/docgen/views/html.js +11 -0
- package/dist/src/docgen/views/pages/cover/cover.js +71 -0
- package/dist/src/docgen/views/pages/cover/pdf-cover.js +24 -0
- package/dist/src/docgen/views/pages/main/main.js +59 -0
- package/dist/src/docgen/views/pages/process-pages.js +170 -0
- package/dist/src/docgen/{html → views}/redirect.js +9 -9
- package/package.json +6 -4
- package/dist/src/docgen/html/process-pages.js +0 -287
- package/dist/src/docgen/html/web-table-of-contents.js +0 -51
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.processPages = exports.processTemplates = void 0;
|
|
43
|
+
var lodash_1 = require("lodash");
|
|
44
|
+
var react_1 = __importDefault(require("react"));
|
|
45
|
+
var picocolors_1 = __importDefault(require("picocolors"));
|
|
46
|
+
var cheerio_1 = __importDefault(require("cheerio"));
|
|
47
|
+
var main_1 = require("./main/main");
|
|
48
|
+
var cover_1 = require("./cover/cover");
|
|
49
|
+
var html_1 = require("../html");
|
|
50
|
+
var pdf_cover_1 = require("./cover/pdf-cover");
|
|
51
|
+
var pdf_footer_1 = require("../components/pdf-footer/pdf-footer");
|
|
52
|
+
var processTemplates = function (_a) {
|
|
53
|
+
var parameters = _a.parameters, mathMathjax = _a.mathMathjax, mathKatex = _a.mathKatex, rawTemplates = _a.templates;
|
|
54
|
+
//Todo: rewrite in non-mutating style (for now just clone)
|
|
55
|
+
var templates = (0, lodash_1.cloneDeep)(rawTemplates);
|
|
56
|
+
//Todo: better way of dynamically setting template <head>
|
|
57
|
+
for (var key in templates) {
|
|
58
|
+
if (templates.hasOwnProperty(key)) {
|
|
59
|
+
var $ = templates[key];
|
|
60
|
+
$('title').text(parameters.title);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (mathKatex === true) {
|
|
64
|
+
var $ = templates.main;
|
|
65
|
+
//support for KaTeX (bundled with DocGen)
|
|
66
|
+
$('head').append('<link rel="stylesheet" href="require/katex/katex.min.css" type="text/css">');
|
|
67
|
+
$('head').append('<script type="text/javascript" src="require/katex/katex.min.js"></script>');
|
|
68
|
+
$('head').append('<script type="text/javascript" src="require/katexInjector.js"></script>');
|
|
69
|
+
}
|
|
70
|
+
if (mathMathjax === true) {
|
|
71
|
+
var $ = templates.main;
|
|
72
|
+
//support for MathJax (only supported via CDN due to very large size)
|
|
73
|
+
//MathJax configuration is the same as used by math.stackexchange.com
|
|
74
|
+
//Note - wkhtmlpdf //cdn urls - see https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1634
|
|
75
|
+
//Note - later than version 2 doesn't work with wkhtmltodpf
|
|
76
|
+
$('head').append("<script type=\"text/javascript\" id=\"MathJax-script\" async\n src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML\">\n </script>");
|
|
77
|
+
}
|
|
78
|
+
return templates;
|
|
79
|
+
};
|
|
80
|
+
exports.processTemplates = processTemplates;
|
|
81
|
+
var processPages = function (_a) {
|
|
82
|
+
var templates = _a.templates, rawPages = _a.pages, sortedPages = _a.sortedPages, parameters = _a.parameters, options = _a.options, contents = _a.contents;
|
|
83
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
84
|
+
var hydratedTemplates, pages, pageTableOfContentsEnabled, tableOfContents, mainTemplate, pdfCoverTemplate, pdfFooterTemplate, webCover, pdfEnabled, webCoverHtml, $, webCoverStyles, pdfCoverHtml, $Pdf, pdfCoverStyles, pdfFooterHtml, $PdfFooter, pdfFooterStyles;
|
|
85
|
+
return __generator(this, function (_b) {
|
|
86
|
+
hydratedTemplates = (0, exports.processTemplates)({
|
|
87
|
+
parameters: parameters,
|
|
88
|
+
templates: templates,
|
|
89
|
+
mathMathjax: options.mathMathjax,
|
|
90
|
+
mathKatex: options.mathKatex,
|
|
91
|
+
});
|
|
92
|
+
pages = (0, lodash_1.cloneDeep)(rawPages);
|
|
93
|
+
pageTableOfContentsEnabled = options.pageToc;
|
|
94
|
+
tableOfContents = contents;
|
|
95
|
+
mainTemplate = hydratedTemplates.main;
|
|
96
|
+
pdfCoverTemplate = hydratedTemplates.pdfCover;
|
|
97
|
+
pdfFooterTemplate = hydratedTemplates.pdfFooter;
|
|
98
|
+
webCover = hydratedTemplates.webCover;
|
|
99
|
+
pdfEnabled = options.pdf;
|
|
100
|
+
console.log(picocolors_1.default.green('Generating the static web content'));
|
|
101
|
+
tableOfContents.forEach(function (section) {
|
|
102
|
+
section.pages.forEach(function (page) {
|
|
103
|
+
var $ = cheerio_1.default.load(mainTemplate.html()); //clone
|
|
104
|
+
var key = page.source;
|
|
105
|
+
var htmlPage = (0, html_1.toHTML)(react_1.default.createElement(main_1.Main, { parameters: parameters, sortedPages: sortedPages, pdfEnabled: pdfEnabled, fixedWidth: page.html !== true }));
|
|
106
|
+
$('body').html(htmlPage);
|
|
107
|
+
//Todo: render the Markdown directly inside the React component
|
|
108
|
+
var content = pages[key];
|
|
109
|
+
$('#dg-innerContent').html(content);
|
|
110
|
+
//------------------------------------------------------------------------------------------------------
|
|
111
|
+
//insert permalinks for every page heading
|
|
112
|
+
//when pageToc is enabled, also insert a page-level table of contents
|
|
113
|
+
var html = [], i = -1;
|
|
114
|
+
var headings = $('h1, h2, h3, h4, h5, h6');
|
|
115
|
+
if (headings.length > 0) {
|
|
116
|
+
html[++i] = '<ul class="dg-pageToc">';
|
|
117
|
+
}
|
|
118
|
+
headings.each(function () {
|
|
119
|
+
var label = $(this).text();
|
|
120
|
+
var anchor = label.toLowerCase().replace(/\s+/g, '-');
|
|
121
|
+
$(this).attr('id', anchor);
|
|
122
|
+
html[++i] = '<li><a href="#' + anchor + '">' + label + '</a></li>';
|
|
123
|
+
});
|
|
124
|
+
if (headings.length > 0) {
|
|
125
|
+
html[++i] = '</ul>';
|
|
126
|
+
}
|
|
127
|
+
if (pageTableOfContentsEnabled === true && page.html !== true) {
|
|
128
|
+
$('#dg-innerContent').prepend(html.join(''));
|
|
129
|
+
}
|
|
130
|
+
//------------------------------------------------------------------------------------------------------
|
|
131
|
+
//prepend the auto heading (which makes the PDF table of contents match the web TOC)
|
|
132
|
+
$('#dg-innerContent').prepend('<h1 id="dg-autoTitle">' + page.title + '</h1>');
|
|
133
|
+
if (page.html === true) {
|
|
134
|
+
$('#dg-autoTitle').addClass('dg-hiddenTitle');
|
|
135
|
+
}
|
|
136
|
+
//------------------------------------------------------------------------------------------------------
|
|
137
|
+
//apply the w-table class
|
|
138
|
+
$('table:not(.unstyled)').addClass('w-table w-fixed w-stripe');
|
|
139
|
+
//------------------------------------------------------------------------------------------------------
|
|
140
|
+
pages[key] = $.html();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
webCoverHtml = (0, html_1.toHTML)(react_1.default.createElement(main_1.Main, { parameters: parameters, sortedPages: sortedPages, pdfEnabled: pdfEnabled },
|
|
144
|
+
react_1.default.createElement(cover_1.Cover, { parameters: parameters })));
|
|
145
|
+
$ = cheerio_1.default.load(mainTemplate.html());
|
|
146
|
+
webCoverStyles = cheerio_1.default.load(webCover.html());
|
|
147
|
+
$('head').append(webCoverStyles('head').html());
|
|
148
|
+
$('body').html(webCoverHtml);
|
|
149
|
+
pdfCoverHtml = (0, html_1.toHTML)(react_1.default.createElement(pdf_cover_1.PdfCover, { parameters: parameters }));
|
|
150
|
+
$Pdf = cheerio_1.default.load(pdfCoverTemplate.html());
|
|
151
|
+
pdfCoverStyles = cheerio_1.default.load(pdfCoverTemplate.html());
|
|
152
|
+
$Pdf('head').append(pdfCoverStyles('head').html());
|
|
153
|
+
$Pdf('body').html(pdfCoverHtml);
|
|
154
|
+
pdfFooterHtml = (0, html_1.toHTML)(react_1.default.createElement(pdf_footer_1.PdfFooter, { parameters: parameters }));
|
|
155
|
+
$PdfFooter = cheerio_1.default.load(pdfFooterTemplate.html());
|
|
156
|
+
pdfFooterStyles = cheerio_1.default.load(pdfFooterTemplate.html());
|
|
157
|
+
$PdfFooter('head').append(pdfFooterStyles('head').html());
|
|
158
|
+
$PdfFooter('body').html(pdfFooterHtml);
|
|
159
|
+
return [2 /*return*/, {
|
|
160
|
+
pages: pages,
|
|
161
|
+
redirect: hydratedTemplates.redirect,
|
|
162
|
+
webCover: $.html(),
|
|
163
|
+
pdfCover: $Pdf.html(),
|
|
164
|
+
pdfHeader: hydratedTemplates.pdfHeader.html(),
|
|
165
|
+
pdfFooter: $PdfFooter.html(),
|
|
166
|
+
}];
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
exports.processPages = processPages;
|
|
@@ -40,27 +40,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.createRedirect = void 0;
|
|
43
|
-
var
|
|
43
|
+
var picocolors_1 = __importDefault(require("picocolors"));
|
|
44
44
|
var path_1 = __importDefault(require("path"));
|
|
45
45
|
var fs_1 = require("../fs/fs");
|
|
46
46
|
var createRedirect = function (_a) {
|
|
47
|
-
var
|
|
47
|
+
var options = _a.options, redirectPage = _a.redirectPage, homePage = _a.homePage;
|
|
48
48
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
49
49
|
var parent_1, homepage, redirectLink, $, file, error_1;
|
|
50
50
|
return __generator(this, function (_b) {
|
|
51
51
|
switch (_b.label) {
|
|
52
52
|
case 0:
|
|
53
|
-
if (!isRedirectEnabled) return [3 /*break*/, 4];
|
|
54
|
-
parent_1 =
|
|
53
|
+
if (!options.isRedirectEnabled) return [3 /*break*/, 4];
|
|
54
|
+
parent_1 = options.output.replace(/\/$/, '');
|
|
55
55
|
parent_1 = parent_1.split(path_1.default.sep).slice(-1).pop(); //get name of final directory in the path
|
|
56
56
|
homepage = homePage;
|
|
57
57
|
homepage =
|
|
58
58
|
homepage.source.substr(0, homepage.source.lastIndexOf('.')) + '.html';
|
|
59
59
|
redirectLink = parent_1 + '/' + homepage;
|
|
60
|
-
$ =
|
|
60
|
+
$ = redirectPage;
|
|
61
61
|
$('a').attr('href', redirectLink);
|
|
62
62
|
$('meta[http-equiv=REFRESH]').attr('content', '0;url=' + redirectLink);
|
|
63
|
-
file =
|
|
63
|
+
file = options.output + '../' + 'index.html';
|
|
64
64
|
_b.label = 1;
|
|
65
65
|
case 1:
|
|
66
66
|
_b.trys.push([1, 3, , 4]);
|
|
@@ -70,9 +70,9 @@ var createRedirect = function (_a) {
|
|
|
70
70
|
return [3 /*break*/, 4];
|
|
71
71
|
case 3:
|
|
72
72
|
error_1 = _b.sent();
|
|
73
|
-
console.log(
|
|
74
|
-
if (verbose === true) {
|
|
75
|
-
console.log(
|
|
73
|
+
console.log(picocolors_1.default.red('Error writing redirect file: ' + file));
|
|
74
|
+
if (options.verbose === true) {
|
|
75
|
+
console.log(picocolors_1.default.red(error_1));
|
|
76
76
|
}
|
|
77
77
|
return [3 /*break*/, 4];
|
|
78
78
|
case 4: return [2 /*return*/];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docgen-tool",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "A tool for creating HTML and PDF documentation",
|
|
5
5
|
"main": "dist/docgen.ts",
|
|
6
6
|
"bin": {
|
|
@@ -34,21 +34,23 @@
|
|
|
34
34
|
"docgen": "prettier --write"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"chalk": "^4.1.0",
|
|
38
37
|
"cheerio": "^1.0.0-rc.12",
|
|
39
38
|
"cli-spinner": "^0.2.10",
|
|
40
39
|
"commander": "^11.0.0",
|
|
41
40
|
"fs-extra": "^11.1.1",
|
|
42
41
|
"husky": "^4.3.0",
|
|
43
|
-
"image-size": "^1.0.2",
|
|
44
42
|
"lint-staged": "^10.5.1",
|
|
43
|
+
"lodash": "^4.17.21",
|
|
45
44
|
"markdown-it": "^13.0.1",
|
|
46
|
-
"
|
|
45
|
+
"picocolors": "^1.0.0",
|
|
46
|
+
"react": "^18.2.0",
|
|
47
|
+
"react-dom": "^18.2.0",
|
|
47
48
|
"spawn-args": "^0.2.0",
|
|
48
49
|
"z-schema": "^6.0.1"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@types/node": "^20.3.1",
|
|
53
|
+
"@types/react": "^18.2.37",
|
|
52
54
|
"eslint": "^8.43.0",
|
|
53
55
|
"eslint-config-prettier": "^8.8.0",
|
|
54
56
|
"ncp": "^2.0.0",
|
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.processPages = exports.insertParameters = void 0;
|
|
43
|
-
var chalk_1 = __importDefault(require("chalk"));
|
|
44
|
-
var cheerio_1 = __importDefault(require("cheerio"));
|
|
45
|
-
var moment_1 = __importDefault(require("moment"));
|
|
46
|
-
var image_size_1 = __importDefault(require("image-size"));
|
|
47
|
-
var insertParameters = function (_a) {
|
|
48
|
-
var inputPath = _a.inputPath, parameters = _a.parameters, setVersion = _a.setVersion, setReleaseDate = _a.setReleaseDate, mathMathjax = _a.mathMathjax, mathKatex = _a.mathKatex, templates = _a.templates, version = _a.version, homeLink = _a.homeLink;
|
|
49
|
-
//------------------------------------------------------------------------------------------------------
|
|
50
|
-
//logo dimensions
|
|
51
|
-
var hasLogo = false;
|
|
52
|
-
var logoWidth = 0;
|
|
53
|
-
var logoHeight = 0;
|
|
54
|
-
var logoPath;
|
|
55
|
-
try {
|
|
56
|
-
logoPath = 'files/images/logo.svg';
|
|
57
|
-
var logo = (0, image_size_1.default)("".concat(inputPath, "/").concat(logoPath));
|
|
58
|
-
logoWidth = logo.width;
|
|
59
|
-
logoHeight = logo.height;
|
|
60
|
-
hasLogo = true;
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
//do nothing. If logo file cannot be read, logo is simply not shown
|
|
64
|
-
}
|
|
65
|
-
if (!hasLogo) {
|
|
66
|
-
//PNG fallback
|
|
67
|
-
try {
|
|
68
|
-
logoPath = 'files/images/logo.png';
|
|
69
|
-
var logo = (0, image_size_1.default)("".concat(inputPath, "/").concat(logoPath));
|
|
70
|
-
logoWidth = logo.width;
|
|
71
|
-
logoHeight = logo.height;
|
|
72
|
-
hasLogo = true;
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
//do nothing. If logo file cannot be read, logo is simply not shown
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
//------------------------------------------------------------------------------------------------------
|
|
79
|
-
//the homepage is the first link in the first heading
|
|
80
|
-
var homelink = homeLink;
|
|
81
|
-
homelink =
|
|
82
|
-
homelink.source.substr(0, homelink.source.lastIndexOf('.')) + '.html';
|
|
83
|
-
var date = (0, moment_1.default)().format('DD/MM/YYYY');
|
|
84
|
-
var time = (0, moment_1.default)().format('HH:mm:ss');
|
|
85
|
-
var year = (0, moment_1.default)().format('YYYY');
|
|
86
|
-
var attribution = 'Created by DocGen ' + version + ' on ' + date + ' at ' + time + '.';
|
|
87
|
-
var releaseVersion = parameters.version;
|
|
88
|
-
if (setVersion !== false) {
|
|
89
|
-
releaseVersion = setVersion;
|
|
90
|
-
}
|
|
91
|
-
var releaseDate = parameters.date;
|
|
92
|
-
if (setReleaseDate !== false) {
|
|
93
|
-
releaseDate = setReleaseDate;
|
|
94
|
-
}
|
|
95
|
-
var author = '';
|
|
96
|
-
if (parameters.author.url !== '') {
|
|
97
|
-
author +=
|
|
98
|
-
'<a href="' +
|
|
99
|
-
parameters.author.url +
|
|
100
|
-
'">' +
|
|
101
|
-
parameters.author.name +
|
|
102
|
-
'</a>';
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
author += parameters.author.name;
|
|
106
|
-
}
|
|
107
|
-
var owner = '';
|
|
108
|
-
if (parameters.owner.url !== '') {
|
|
109
|
-
owner +=
|
|
110
|
-
'<a href="' +
|
|
111
|
-
parameters.owner.url +
|
|
112
|
-
'">' +
|
|
113
|
-
parameters.owner.name +
|
|
114
|
-
'</a>';
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
owner += parameters.owner.name;
|
|
118
|
-
}
|
|
119
|
-
var organization = '';
|
|
120
|
-
if (parameters.organization.url !== '') {
|
|
121
|
-
organization +=
|
|
122
|
-
'<a href="' +
|
|
123
|
-
parameters.organization.url +
|
|
124
|
-
'">' +
|
|
125
|
-
parameters.organization.name +
|
|
126
|
-
'</a>';
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
organization += parameters.organization.name;
|
|
130
|
-
}
|
|
131
|
-
var website = '';
|
|
132
|
-
if (parameters.website.url !== '') {
|
|
133
|
-
website +=
|
|
134
|
-
'<a href="' +
|
|
135
|
-
parameters.website.url +
|
|
136
|
-
'">' +
|
|
137
|
-
parameters.website.name +
|
|
138
|
-
'</a>';
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
website += parameters.website.name;
|
|
142
|
-
}
|
|
143
|
-
var backlink = '';
|
|
144
|
-
if (parameters.backlink.url !== '') {
|
|
145
|
-
backlink +=
|
|
146
|
-
'<a class="button inverted" href="' +
|
|
147
|
-
parameters.backlink.url +
|
|
148
|
-
'">' +
|
|
149
|
-
parameters.backlink.name +
|
|
150
|
-
'</a>';
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
backlink += parameters.backlink.name;
|
|
154
|
-
}
|
|
155
|
-
var sponsorLink = '';
|
|
156
|
-
if (parameters.sponsorLink) {
|
|
157
|
-
sponsorLink = "\n <div id=\"headerSponsor\">\n <span>".concat(parameters.sponsorLink.name, "</span>\n <a href=\"").concat(parameters.sponsorLink.url, "\">\n <img id=\"sponsorLogo\" src=\"").concat(parameters.sponsorLink.logo, "\" alt=\"sponsor logo\">\n </a>\n </div>\n ");
|
|
158
|
-
}
|
|
159
|
-
var contributors = '';
|
|
160
|
-
parameters.contributors.forEach(function (contributor) {
|
|
161
|
-
if (contributor.url !== '') {
|
|
162
|
-
contributors +=
|
|
163
|
-
'<a href="' + contributor.url + '">' + contributor.name + '</a>, ';
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
contributors += contributor.name + ', ';
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
contributors = contributors.replace(/,\s*$/, ''); //remove trailing commas
|
|
170
|
-
var copyright = '© ' + year + ' ' + organization;
|
|
171
|
-
var webTitle = parameters.title;
|
|
172
|
-
var webFooter = 'Version ' + releaseVersion + ' released on ' + releaseDate + '.';
|
|
173
|
-
for (var key in templates) {
|
|
174
|
-
if (templates.hasOwnProperty(key)) {
|
|
175
|
-
var $ = templates[key];
|
|
176
|
-
//logo
|
|
177
|
-
if (hasLogo === true) {
|
|
178
|
-
var logoUrl = logoPath;
|
|
179
|
-
$('#dg-logo').css('background-image', 'url(' + logoUrl + ')');
|
|
180
|
-
$('#dg-logo').css('height', logoHeight + 'px');
|
|
181
|
-
$('#dg-logo').css('padding-left', logoWidth + 25 + 'px');
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
$('#dg-logo').css('padding-left', '0');
|
|
185
|
-
}
|
|
186
|
-
//parameters
|
|
187
|
-
$('title').text(parameters.title);
|
|
188
|
-
$('.dg-homelink').attr('href', homelink);
|
|
189
|
-
$('#dg-title').text(parameters.title);
|
|
190
|
-
$('#dg-owner').html(owner);
|
|
191
|
-
$('#dg-version').text(releaseVersion);
|
|
192
|
-
$('#dg-web-title-version').text('(' + releaseVersion + ')');
|
|
193
|
-
$('#dg-release-date').text(releaseDate);
|
|
194
|
-
$('#dg-web-footer').text(webFooter);
|
|
195
|
-
$('#dg-author').html(author);
|
|
196
|
-
$('#dg-contributors').html(contributors);
|
|
197
|
-
$('#dg-module').text(parameters.module);
|
|
198
|
-
$('#dg-id').html(parameters.id);
|
|
199
|
-
$('#dg-website').html(website);
|
|
200
|
-
$('#dg-backlink').html(backlink);
|
|
201
|
-
$('#headerLeftText').append(sponsorLink);
|
|
202
|
-
$('#dg-summary').text(parameters.summary);
|
|
203
|
-
$('#dg-copyright').html(copyright);
|
|
204
|
-
$('#dg-marking').text(parameters.marking);
|
|
205
|
-
$('#dg-legalese').text(parameters.legalese);
|
|
206
|
-
$('#dg-attribution').text(attribution);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (mathKatex === true) {
|
|
210
|
-
var $ = templates.main;
|
|
211
|
-
//support for KaTeX (bundled with DocGen)
|
|
212
|
-
$('head').append('<link rel="stylesheet" href="require/katex/katex.min.css" type="text/css">');
|
|
213
|
-
$('head').append('<script type="text/javascript" src="require/katex/katex.min.js"></script>');
|
|
214
|
-
$('head').append('<script type="text/javascript" src="require/katexInjector.js"></script>');
|
|
215
|
-
}
|
|
216
|
-
if (mathMathjax === true) {
|
|
217
|
-
var $ = templates.main;
|
|
218
|
-
//support for MathJax (only supported via CDN due to very large size)
|
|
219
|
-
//MathJax configuration is the same as used by math.stackexchange.com
|
|
220
|
-
//Note - wkhtmlpdf //cdn urls - see https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1634
|
|
221
|
-
//Note - later than version 2 doesn't work with wkhtmltodpf
|
|
222
|
-
$('head').append("<script type=\"text/javascript\" id=\"MathJax-script\" async\n src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML\">\n </script>");
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
exports.insertParameters = insertParameters;
|
|
226
|
-
var processPages = function (_a) {
|
|
227
|
-
var pages = _a.pages, pageTableOfContentsEnabled = _a.pageTableOfContentsEnabled, tableOfContents = _a.tableOfContents, mainTemplate = _a.mainTemplate, webCover = _a.webCover;
|
|
228
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
229
|
-
var $;
|
|
230
|
-
return __generator(this, function (_b) {
|
|
231
|
-
console.log(chalk_1.default.green('Generating the static web content'));
|
|
232
|
-
tableOfContents.forEach(function (section) {
|
|
233
|
-
section.pages.forEach(function (page) {
|
|
234
|
-
var $ = cheerio_1.default.load(mainTemplate.html()); //clone
|
|
235
|
-
var key = page.source;
|
|
236
|
-
var content = pages[key];
|
|
237
|
-
//add relevant container
|
|
238
|
-
if (page.html === true) {
|
|
239
|
-
//raw HTML pages should not be confined to the fixed width
|
|
240
|
-
$('#dg-content').html('<div id="dg-innerContent"></div>');
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
//Markdown pages should be confined to the fixed width
|
|
244
|
-
$('#dg-content').html('<div class="w-fixed-width"><div id="dg-innerContent"></div></div>');
|
|
245
|
-
}
|
|
246
|
-
$('#dg-innerContent').html(content);
|
|
247
|
-
//------------------------------------------------------------------------------------------------------
|
|
248
|
-
//insert permalinks for every page heading
|
|
249
|
-
//when pageToc is enabled, also insert a page-level table of contents
|
|
250
|
-
var html = [], i = -1;
|
|
251
|
-
var headings = $('h1, h2, h3, h4, h5, h6');
|
|
252
|
-
if (headings.length > 0) {
|
|
253
|
-
html[++i] = '<ul class="dg-pageToc">';
|
|
254
|
-
}
|
|
255
|
-
headings.each(function () {
|
|
256
|
-
var label = $(this).text();
|
|
257
|
-
var anchor = label.toLowerCase().replace(/\s+/g, '-');
|
|
258
|
-
$(this).attr('id', anchor);
|
|
259
|
-
html[++i] = '<li><a href="#' + anchor + '">' + label + '</a></li>';
|
|
260
|
-
});
|
|
261
|
-
if (headings.length > 0) {
|
|
262
|
-
html[++i] = '</ul>';
|
|
263
|
-
}
|
|
264
|
-
if (pageTableOfContentsEnabled === true && page.html !== true) {
|
|
265
|
-
$('#dg-innerContent').prepend(html.join(''));
|
|
266
|
-
}
|
|
267
|
-
//------------------------------------------------------------------------------------------------------
|
|
268
|
-
//prepend the auto heading (which makes the PDF table of contents match the web TOC)
|
|
269
|
-
$('#dg-innerContent').prepend('<h1 id="dg-autoTitle">' + page.title + '</h1>');
|
|
270
|
-
if (page.html === true) {
|
|
271
|
-
$('#dg-autoTitle').addClass('dg-hiddenTitle');
|
|
272
|
-
}
|
|
273
|
-
//------------------------------------------------------------------------------------------------------
|
|
274
|
-
//apply the w-table class
|
|
275
|
-
$('table:not(.unstyled)').addClass('w-table w-fixed w-stripe');
|
|
276
|
-
//------------------------------------------------------------------------------------------------------
|
|
277
|
-
pages[key] = $;
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
$ = cheerio_1.default.load(mainTemplate.html());
|
|
281
|
-
$('#dg-content').html('<div class="w-fixed-width"><div id="dg-innerContent"></div></div>');
|
|
282
|
-
$('#dg-innerContent').html(webCover.html());
|
|
283
|
-
return [2 /*return*/, $];
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
};
|
|
287
|
-
exports.processPages = processPages;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateWebTableOfContents = void 0;
|
|
4
|
-
var generateWebTableOfContents = function (_a) {
|
|
5
|
-
var sortedPages = _a.sortedPages, mainTemplate = _a.mainTemplate, name = _a.name, pdfEnabled = _a.pdfEnabled;
|
|
6
|
-
var pdfName = name.toLowerCase() + '.pdf';
|
|
7
|
-
var $ = mainTemplate;
|
|
8
|
-
var html = [], i = -1;
|
|
9
|
-
html[++i] = '<div><table class="unstyled"><tr>';
|
|
10
|
-
//build the contents HTML
|
|
11
|
-
for (var key in sortedPages) {
|
|
12
|
-
if (sortedPages.hasOwnProperty(key)) {
|
|
13
|
-
if (key !== String(5)) {
|
|
14
|
-
//skip the extra column
|
|
15
|
-
html[++i] = '<td class="dg-tocGroup">';
|
|
16
|
-
sortedPages[key].forEach(function (section) {
|
|
17
|
-
html[++i] =
|
|
18
|
-
'<ul><li class="dg-tocHeading">' + section.heading + '</li>';
|
|
19
|
-
section.pages.forEach(function (page) {
|
|
20
|
-
var name = page.source.substr(0, page.source.lastIndexOf('.'));
|
|
21
|
-
var path = name + '.html';
|
|
22
|
-
html[++i] =
|
|
23
|
-
'<li><a href="' + path + '">' + page.title + '</a></li>';
|
|
24
|
-
});
|
|
25
|
-
html[++i] = '</li></ul>';
|
|
26
|
-
});
|
|
27
|
-
html[++i] = '</td>';
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
//fixed-width column at end
|
|
32
|
-
html[++i] = '<td class="dg-tocGroup" id="dg-tocFixedColumn"><ul>';
|
|
33
|
-
html[++i] =
|
|
34
|
-
'<li><span class="w-icon dg-tocIcon" data-name="person_group" title="archive"></span><a href="ownership.html">Ownership</a></li>';
|
|
35
|
-
html[++i] =
|
|
36
|
-
'<li><span class="w-icon dg-tocIcon" data-name="refresh" title="archive"></span><a href="release-notes.html">Release Notes</a></li>';
|
|
37
|
-
html[++i] = '</ul><div>';
|
|
38
|
-
if (pdfEnabled) {
|
|
39
|
-
html[++i] =
|
|
40
|
-
'<button class="whiteInverted" onclick="window.location=\'' +
|
|
41
|
-
pdfName +
|
|
42
|
-
'\';">';
|
|
43
|
-
html[++i] = '<span>PDF</span>';
|
|
44
|
-
html[++i] = '</button>';
|
|
45
|
-
}
|
|
46
|
-
html[++i] = '</div></td>';
|
|
47
|
-
html[++i] = '</tr></table></div>';
|
|
48
|
-
$('#dg-toc').html(html.join(''));
|
|
49
|
-
return $;
|
|
50
|
-
};
|
|
51
|
-
exports.generateWebTableOfContents = generateWebTableOfContents;
|