hdoc-tools 0.60.1 → 0.62.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/LICENSE +21 -21
- package/README.md +89 -75
- package/hdoc-build-db.js +275 -275
- package/hdoc-build-embeddings.js +202 -202
- package/hdoc-build-pdf.js +232 -232
- package/hdoc-build.js +14 -6
- package/hdoc-bump.js +4 -2
- package/hdoc-content-routes.js +143 -83
- package/hdoc-create.js +110 -108
- package/hdoc-db.js +114 -114
- package/hdoc-help.js +60 -60
- package/hdoc-init.js +103 -68
- package/hdoc-install-browser.js +145 -145
- package/hdoc-mermaid.js +204 -204
- package/hdoc-module.js +1102 -1079
- package/hdoc-serve.js +13 -7
- package/hdoc-stats.js +9 -9
- package/hdoc-validate-config.js +355 -329
- package/hdoc-validate-interbook.js +321 -0
- package/hdoc-validate.js +1231 -1158
- package/hdoc-ver.js +4 -2
- package/hdoc.js +12 -11
- package/npm-shrinkwrap.json +2 -2
- package/package.json +13 -2
- package/schemas/hdocbook-project.schema.json +20 -0
- package/schemas/hdocbook.schema.json +6 -2
- package/templates/doc-header-non-git.html +19 -19
- package/templates/doc-header.html +26 -26
- package/templates/init/.github/workflows/hdocbuild_onpull.yml +16 -16
- package/templates/init/.github/workflows/hdocbuild_onpush.yml +15 -15
- package/templates/init/LICENSE +21 -21
- package/templates/init/README.md +9 -9
- package/templates/init/_hdocbook/index.md +4 -4
- package/templates/init/gitignore +8 -8
- package/templates/init/resources/README.md +2 -2
- package/templates/pdf/css/custom-block.css +90 -90
- package/templates/pdf/css/fonts.css +221 -221
- package/templates/pdf/css/hdocs-pdf.css +495 -495
- package/templates/pdf/css/vars.css +404 -404
- package/templates/pdf/template-footer.html +19 -19
- package/templates/pdf/template-header.html +37 -37
- package/templates/pdf/template.html +20 -20
- package/templates/pdf-header-non-git.html +12 -12
- package/templates/pdf-header.html +16 -16
- package/ui/content/invalid-hdocbook-json.html +6 -6
- package/ui/content/invalid-hdocbook-json.md +7 -7
- package/ui/css/theme-default/styles/components/content.css +124 -124
- package/ui/css/theme-default/styles/components/sidebar.css +182 -182
- package/ui/css/theme-default/styles/htldoc.layouts.css +310 -310
- package/ui/index.html +419 -419
- package/ui/js/doc.hornbill.js +31 -44
- package/ui/js/mermaid-theme.json +27 -0
- package/hdoc-build-onyx.js +0 -134
- package/templates/mermaid-theme.yaml +0 -28
- package/templates/pdf/fonts/inter-cyrillic copy.woff2 +0 -0
package/hdoc-build-pdf.js
CHANGED
|
@@ -1,232 +1,232 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
const cheerio = require("cheerio");
|
|
3
|
-
const fs = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const hdoc = require(path.join(__dirname, "hdoc-module.js"));
|
|
6
|
-
|
|
7
|
-
let hb_logo = "";
|
|
8
|
-
let footer = "";
|
|
9
|
-
let header = "";
|
|
10
|
-
|
|
11
|
-
const get_footer = (template_path) => {
|
|
12
|
-
let footer_content = null;
|
|
13
|
-
try {
|
|
14
|
-
footer_content = fs.readFileSync(
|
|
15
|
-
path.join(template_path, "template-footer.html"),
|
|
16
|
-
"utf8",
|
|
17
|
-
);
|
|
18
|
-
} catch (err) {
|
|
19
|
-
console.error(`Error loading template: ${err}`);
|
|
20
|
-
}
|
|
21
|
-
return footer_content;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const get_header = (template_path) => {
|
|
25
|
-
let header_content = null;
|
|
26
|
-
try {
|
|
27
|
-
header_content = fs.readFileSync(
|
|
28
|
-
path.join(template_path, "template-header.html"),
|
|
29
|
-
"utf8",
|
|
30
|
-
);
|
|
31
|
-
} catch (err) {
|
|
32
|
-
console.error(`Error loading template: ${err}`);
|
|
33
|
-
}
|
|
34
|
-
return header_content;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
exports.process_images = async (file_path, html_source, verbose) => {
|
|
38
|
-
const book_work_root = file_path.path.replace(file_path.relativePath, "");
|
|
39
|
-
if (verbose) console.log("Parsing img tags from HTML source");
|
|
40
|
-
|
|
41
|
-
let processed_html_source = html_source;
|
|
42
|
-
// Use cheerio to parse html
|
|
43
|
-
const $ = cheerio.load(processed_html_source);
|
|
44
|
-
|
|
45
|
-
// Get iFrames from HTML, to replace with a tags
|
|
46
|
-
const iframes = [];
|
|
47
|
-
const iframe_html = $("iframe")
|
|
48
|
-
.map(function () {
|
|
49
|
-
const response = {
|
|
50
|
-
html: $.html(this),
|
|
51
|
-
src: $(this).attr("src"),
|
|
52
|
-
title: $(this).attr("title")
|
|
53
|
-
? $(this).attr("title")
|
|
54
|
-
: "No Link Title Provided",
|
|
55
|
-
};
|
|
56
|
-
return response;
|
|
57
|
-
})
|
|
58
|
-
.get();
|
|
59
|
-
iframes.push(...iframe_html);
|
|
60
|
-
for (let i = 0; i < iframes.length; i++) {
|
|
61
|
-
const link = `<p><a href="${iframes[i].src}">${iframes[i].title}</a></p>`;
|
|
62
|
-
const regex = new RegExp(
|
|
63
|
-
`<iframe.*src="${iframes[i].src.replace("/", "\\/")}".*</iframe>`,
|
|
64
|
-
);
|
|
65
|
-
processed_html_source = processed_html_source.replace(regex, link);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Get image links from HTML, to embed into the pdf
|
|
69
|
-
const imgs = [];
|
|
70
|
-
const srcs = $("img")
|
|
71
|
-
.map(function (i) {
|
|
72
|
-
return $(this).attr("src");
|
|
73
|
-
})
|
|
74
|
-
.get();
|
|
75
|
-
imgs.push(...srcs);
|
|
76
|
-
for (let i = 0; i < imgs.length; i++) {
|
|
77
|
-
if (!hdoc.valid_url(imgs[i])) {
|
|
78
|
-
// Internal link
|
|
79
|
-
const image_path = path.join(
|
|
80
|
-
book_work_root,
|
|
81
|
-
imgs[i].replace("_books/", ""),
|
|
82
|
-
);
|
|
83
|
-
try {
|
|
84
|
-
const image_buffer = fs.readFileSync(image_path);
|
|
85
|
-
// Inline MIME type lookup for image formats commonly found in documentation.
|
|
86
|
-
// Falls back to application/octet-stream for any unrecognised extension so the
|
|
87
|
-
// base64 data URI is still well-formed even if the browser can't render it.
|
|
88
|
-
const mime_type = ({ '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.svg': 'image/svg+xml', '.webp': 'image/webp', '.bmp': 'image/bmp', '.ico': 'image/x-icon' })[path.extname(image_path).toLowerCase()] || 'application/octet-stream';
|
|
89
|
-
let image_b64 = image_buffer.toString("base64");
|
|
90
|
-
image_b64 = `data:${mime_type};base64,${image_b64}`;
|
|
91
|
-
processed_html_source = processed_html_source.replace(
|
|
92
|
-
imgs[i],
|
|
93
|
-
image_b64,
|
|
94
|
-
);
|
|
95
|
-
} catch (err) {
|
|
96
|
-
console.error(
|
|
97
|
-
"Error reading image from HTML source [",
|
|
98
|
-
image_path,
|
|
99
|
-
"] -",
|
|
100
|
-
err,
|
|
101
|
-
);
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
// External Link
|
|
106
|
-
try {
|
|
107
|
-
const file_response = await fetch(imgs[i]);
|
|
108
|
-
if (file_response.status === 200) {
|
|
109
|
-
let image_b64 = imageEncode(await file_response.arrayBuffer(), file_response.headers.get('content-type'));
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const regexQ = `<img\\s+[^>]*src=["']${imgs[i].replaceAll('/', '\\/').replaceAll('.', '\\.')}["'][^>]*>`;
|
|
113
|
-
const regex = new RegExp(regexQ);
|
|
114
|
-
|
|
115
|
-
const found_img_tag = processed_html_source.match(regex);
|
|
116
|
-
const new_img_tag = found_img_tag[0].replace(imgs[i], image_b64);
|
|
117
|
-
|
|
118
|
-
processed_html_source = processed_html_source.replace(
|
|
119
|
-
found_img_tag,
|
|
120
|
-
new_img_tag,
|
|
121
|
-
);
|
|
122
|
-
} else {
|
|
123
|
-
throw `Unexpected Status ${file_response.status}`;
|
|
124
|
-
}
|
|
125
|
-
} catch (err) {
|
|
126
|
-
console.error(
|
|
127
|
-
`Error downloading external source [${imgs[i]}] - ${err}`,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return processed_html_source;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const imageEncode = (arrayBuffer, mimeType) => {
|
|
137
|
-
let u8 = new Uint8Array(arrayBuffer)
|
|
138
|
-
let b64encoded = btoa([].reduce.call(new Uint8Array(arrayBuffer),function(p,c){return p+String.fromCharCode(c)},''))
|
|
139
|
-
let mimetype=`image/${mimeType}`
|
|
140
|
-
return "data:"+mimetype+";base64,"+b64encoded
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
exports.generate_pdf = async (
|
|
144
|
-
browser,
|
|
145
|
-
pdf_template_path,
|
|
146
|
-
pdf_template_content,
|
|
147
|
-
book_config,
|
|
148
|
-
html_source,
|
|
149
|
-
target_file,
|
|
150
|
-
css_templates,
|
|
151
|
-
verbose = false,
|
|
152
|
-
) => {
|
|
153
|
-
let pdf_size = 0;
|
|
154
|
-
// Cache footer
|
|
155
|
-
if (footer === "") footer = get_footer(pdf_template_path);
|
|
156
|
-
|
|
157
|
-
// Read svg logo file into buffer, convert to B64 string
|
|
158
|
-
if (hb_logo === "") {
|
|
159
|
-
const hb_logo_path = path.join(
|
|
160
|
-
pdf_template_path,
|
|
161
|
-
"images",
|
|
162
|
-
"hornbill-logo-full.svg",
|
|
163
|
-
);
|
|
164
|
-
try {
|
|
165
|
-
const hb_logo_file_buffer = fs.readFileSync(hb_logo_path);
|
|
166
|
-
hb_logo = hb_logo_file_buffer.toString("base64");
|
|
167
|
-
hb_logo = `data:image/svg+xml;base64,${hb_logo}`;
|
|
168
|
-
} catch (err) {
|
|
169
|
-
console.error("Error reading logo from template:", err);
|
|
170
|
-
return pdf_size;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Cache header
|
|
175
|
-
if (header === "") {
|
|
176
|
-
header = get_header(pdf_template_path)
|
|
177
|
-
.replace("{{book_title}}", book_config.title)
|
|
178
|
-
.replace("{{hb_logo}}", hb_logo);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const processed_html_source = pdf_template_content
|
|
182
|
-
.replace("{{book_title}}", book_config.title)
|
|
183
|
-
.replace("{{document_content}}", html_source);
|
|
184
|
-
|
|
185
|
-
const page = await browser.newPage();
|
|
186
|
-
|
|
187
|
-
// To reflect CSS used for screens instead of print
|
|
188
|
-
await page.emulateMediaType("screen");
|
|
189
|
-
|
|
190
|
-
// Set HTML content from HTML source
|
|
191
|
-
await page.setContent(processed_html_source, {
|
|
192
|
-
waitUntil: "domcontentloaded",
|
|
193
|
-
});
|
|
194
|
-
for (let i = 0; i < css_templates.length; i++) {
|
|
195
|
-
try {
|
|
196
|
-
await page.addStyleTag({
|
|
197
|
-
content: css_templates[i],
|
|
198
|
-
});
|
|
199
|
-
} catch (e) {
|
|
200
|
-
console.error(`Error applying template for [${target_file}]: ${e}`);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
try {
|
|
205
|
-
const pdf_gen = await page.pdf({
|
|
206
|
-
path: target_file,
|
|
207
|
-
printBackground: true,
|
|
208
|
-
format: "A4",
|
|
209
|
-
displayHeaderFooter: true,
|
|
210
|
-
headerTemplate: header,
|
|
211
|
-
footerTemplate: footer,
|
|
212
|
-
margin: {
|
|
213
|
-
top: "90px",
|
|
214
|
-
right: "30px",
|
|
215
|
-
bottom: "60px",
|
|
216
|
-
left: "30px",
|
|
217
|
-
},
|
|
218
|
-
timeout: 0,
|
|
219
|
-
});
|
|
220
|
-
const currdate = new Date();
|
|
221
|
-
const datetime = currdate.toISOString();
|
|
222
|
-
if (verbose)
|
|
223
|
-
console.log(`[${datetime}] PDF generation success: ${target_file}`);
|
|
224
|
-
|
|
225
|
-
pdf_size = pdf_gen.byteLength;
|
|
226
|
-
} catch (err) {
|
|
227
|
-
console.error(`Error generating PDF ${target_file} - ${err}`);
|
|
228
|
-
}
|
|
229
|
-
await page.close();
|
|
230
|
-
return pdf_size;
|
|
231
|
-
};
|
|
232
|
-
})();
|
|
1
|
+
(() => {
|
|
2
|
+
const cheerio = require("cheerio");
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const hdoc = require(path.join(__dirname, "hdoc-module.js"));
|
|
6
|
+
|
|
7
|
+
let hb_logo = "";
|
|
8
|
+
let footer = "";
|
|
9
|
+
let header = "";
|
|
10
|
+
|
|
11
|
+
const get_footer = (template_path) => {
|
|
12
|
+
let footer_content = null;
|
|
13
|
+
try {
|
|
14
|
+
footer_content = fs.readFileSync(
|
|
15
|
+
path.join(template_path, "template-footer.html"),
|
|
16
|
+
"utf8",
|
|
17
|
+
);
|
|
18
|
+
} catch (err) {
|
|
19
|
+
console.error(`Error loading template: ${err}`);
|
|
20
|
+
}
|
|
21
|
+
return footer_content;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const get_header = (template_path) => {
|
|
25
|
+
let header_content = null;
|
|
26
|
+
try {
|
|
27
|
+
header_content = fs.readFileSync(
|
|
28
|
+
path.join(template_path, "template-header.html"),
|
|
29
|
+
"utf8",
|
|
30
|
+
);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error(`Error loading template: ${err}`);
|
|
33
|
+
}
|
|
34
|
+
return header_content;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.process_images = async (file_path, html_source, verbose) => {
|
|
38
|
+
const book_work_root = file_path.path.replace(file_path.relativePath, "");
|
|
39
|
+
if (verbose) console.log("Parsing img tags from HTML source");
|
|
40
|
+
|
|
41
|
+
let processed_html_source = html_source;
|
|
42
|
+
// Use cheerio to parse html
|
|
43
|
+
const $ = cheerio.load(processed_html_source);
|
|
44
|
+
|
|
45
|
+
// Get iFrames from HTML, to replace with a tags
|
|
46
|
+
const iframes = [];
|
|
47
|
+
const iframe_html = $("iframe")
|
|
48
|
+
.map(function () {
|
|
49
|
+
const response = {
|
|
50
|
+
html: $.html(this),
|
|
51
|
+
src: $(this).attr("src"),
|
|
52
|
+
title: $(this).attr("title")
|
|
53
|
+
? $(this).attr("title")
|
|
54
|
+
: "No Link Title Provided",
|
|
55
|
+
};
|
|
56
|
+
return response;
|
|
57
|
+
})
|
|
58
|
+
.get();
|
|
59
|
+
iframes.push(...iframe_html);
|
|
60
|
+
for (let i = 0; i < iframes.length; i++) {
|
|
61
|
+
const link = `<p><a href="${iframes[i].src}">${iframes[i].title}</a></p>`;
|
|
62
|
+
const regex = new RegExp(
|
|
63
|
+
`<iframe.*src="${iframes[i].src.replace("/", "\\/")}".*</iframe>`,
|
|
64
|
+
);
|
|
65
|
+
processed_html_source = processed_html_source.replace(regex, link);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Get image links from HTML, to embed into the pdf
|
|
69
|
+
const imgs = [];
|
|
70
|
+
const srcs = $("img")
|
|
71
|
+
.map(function (i) {
|
|
72
|
+
return $(this).attr("src");
|
|
73
|
+
})
|
|
74
|
+
.get();
|
|
75
|
+
imgs.push(...srcs);
|
|
76
|
+
for (let i = 0; i < imgs.length; i++) {
|
|
77
|
+
if (!hdoc.valid_url(imgs[i])) {
|
|
78
|
+
// Internal link
|
|
79
|
+
const image_path = path.join(
|
|
80
|
+
book_work_root,
|
|
81
|
+
imgs[i].replace("_books/", ""),
|
|
82
|
+
);
|
|
83
|
+
try {
|
|
84
|
+
const image_buffer = fs.readFileSync(image_path);
|
|
85
|
+
// Inline MIME type lookup for image formats commonly found in documentation.
|
|
86
|
+
// Falls back to application/octet-stream for any unrecognised extension so the
|
|
87
|
+
// base64 data URI is still well-formed even if the browser can't render it.
|
|
88
|
+
const mime_type = ({ '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.svg': 'image/svg+xml', '.webp': 'image/webp', '.bmp': 'image/bmp', '.ico': 'image/x-icon' })[path.extname(image_path).toLowerCase()] || 'application/octet-stream';
|
|
89
|
+
let image_b64 = image_buffer.toString("base64");
|
|
90
|
+
image_b64 = `data:${mime_type};base64,${image_b64}`;
|
|
91
|
+
processed_html_source = processed_html_source.replace(
|
|
92
|
+
imgs[i],
|
|
93
|
+
image_b64,
|
|
94
|
+
);
|
|
95
|
+
} catch (err) {
|
|
96
|
+
console.error(
|
|
97
|
+
"Error reading image from HTML source [",
|
|
98
|
+
image_path,
|
|
99
|
+
"] -",
|
|
100
|
+
err,
|
|
101
|
+
);
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
// External Link
|
|
106
|
+
try {
|
|
107
|
+
const file_response = await fetch(imgs[i]);
|
|
108
|
+
if (file_response.status === 200) {
|
|
109
|
+
let image_b64 = imageEncode(await file_response.arrayBuffer(), file_response.headers.get('content-type'));
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
const regexQ = `<img\\s+[^>]*src=["']${imgs[i].replaceAll('/', '\\/').replaceAll('.', '\\.')}["'][^>]*>`;
|
|
113
|
+
const regex = new RegExp(regexQ);
|
|
114
|
+
|
|
115
|
+
const found_img_tag = processed_html_source.match(regex);
|
|
116
|
+
const new_img_tag = found_img_tag[0].replace(imgs[i], image_b64);
|
|
117
|
+
|
|
118
|
+
processed_html_source = processed_html_source.replace(
|
|
119
|
+
found_img_tag,
|
|
120
|
+
new_img_tag,
|
|
121
|
+
);
|
|
122
|
+
} else {
|
|
123
|
+
throw `Unexpected Status ${file_response.status}`;
|
|
124
|
+
}
|
|
125
|
+
} catch (err) {
|
|
126
|
+
console.error(
|
|
127
|
+
`Error downloading external source [${imgs[i]}] - ${err}`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return processed_html_source;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const imageEncode = (arrayBuffer, mimeType) => {
|
|
137
|
+
let u8 = new Uint8Array(arrayBuffer)
|
|
138
|
+
let b64encoded = btoa([].reduce.call(new Uint8Array(arrayBuffer),function(p,c){return p+String.fromCharCode(c)},''))
|
|
139
|
+
let mimetype=`image/${mimeType}`
|
|
140
|
+
return "data:"+mimetype+";base64,"+b64encoded
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
exports.generate_pdf = async (
|
|
144
|
+
browser,
|
|
145
|
+
pdf_template_path,
|
|
146
|
+
pdf_template_content,
|
|
147
|
+
book_config,
|
|
148
|
+
html_source,
|
|
149
|
+
target_file,
|
|
150
|
+
css_templates,
|
|
151
|
+
verbose = false,
|
|
152
|
+
) => {
|
|
153
|
+
let pdf_size = 0;
|
|
154
|
+
// Cache footer
|
|
155
|
+
if (footer === "") footer = get_footer(pdf_template_path);
|
|
156
|
+
|
|
157
|
+
// Read svg logo file into buffer, convert to B64 string
|
|
158
|
+
if (hb_logo === "") {
|
|
159
|
+
const hb_logo_path = path.join(
|
|
160
|
+
pdf_template_path,
|
|
161
|
+
"images",
|
|
162
|
+
"hornbill-logo-full.svg",
|
|
163
|
+
);
|
|
164
|
+
try {
|
|
165
|
+
const hb_logo_file_buffer = fs.readFileSync(hb_logo_path);
|
|
166
|
+
hb_logo = hb_logo_file_buffer.toString("base64");
|
|
167
|
+
hb_logo = `data:image/svg+xml;base64,${hb_logo}`;
|
|
168
|
+
} catch (err) {
|
|
169
|
+
console.error("Error reading logo from template:", err);
|
|
170
|
+
return pdf_size;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Cache header
|
|
175
|
+
if (header === "") {
|
|
176
|
+
header = get_header(pdf_template_path)
|
|
177
|
+
.replace("{{book_title}}", book_config.title)
|
|
178
|
+
.replace("{{hb_logo}}", hb_logo);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const processed_html_source = pdf_template_content
|
|
182
|
+
.replace("{{book_title}}", book_config.title)
|
|
183
|
+
.replace("{{document_content}}", html_source);
|
|
184
|
+
|
|
185
|
+
const page = await browser.newPage();
|
|
186
|
+
|
|
187
|
+
// To reflect CSS used for screens instead of print
|
|
188
|
+
await page.emulateMediaType("screen");
|
|
189
|
+
|
|
190
|
+
// Set HTML content from HTML source
|
|
191
|
+
await page.setContent(processed_html_source, {
|
|
192
|
+
waitUntil: "domcontentloaded",
|
|
193
|
+
});
|
|
194
|
+
for (let i = 0; i < css_templates.length; i++) {
|
|
195
|
+
try {
|
|
196
|
+
await page.addStyleTag({
|
|
197
|
+
content: css_templates[i],
|
|
198
|
+
});
|
|
199
|
+
} catch (e) {
|
|
200
|
+
console.error(`Error applying template for [${target_file}]: ${e}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
const pdf_gen = await page.pdf({
|
|
206
|
+
path: target_file,
|
|
207
|
+
printBackground: true,
|
|
208
|
+
format: "A4",
|
|
209
|
+
displayHeaderFooter: true,
|
|
210
|
+
headerTemplate: header,
|
|
211
|
+
footerTemplate: footer,
|
|
212
|
+
margin: {
|
|
213
|
+
top: "90px",
|
|
214
|
+
right: "30px",
|
|
215
|
+
bottom: "60px",
|
|
216
|
+
left: "30px",
|
|
217
|
+
},
|
|
218
|
+
timeout: 0,
|
|
219
|
+
});
|
|
220
|
+
const currdate = new Date();
|
|
221
|
+
const datetime = currdate.toISOString();
|
|
222
|
+
if (verbose)
|
|
223
|
+
console.log(`[${datetime}] PDF generation success: ${target_file}`);
|
|
224
|
+
|
|
225
|
+
pdf_size = pdf_gen.byteLength;
|
|
226
|
+
} catch (err) {
|
|
227
|
+
console.error(`Error generating PDF ${target_file} - ${err}`);
|
|
228
|
+
}
|
|
229
|
+
await page.close();
|
|
230
|
+
return pdf_size;
|
|
231
|
+
};
|
|
232
|
+
})();
|
package/hdoc-build.js
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
const hdoc = require(path.join(__dirname, "hdoc-module.js"));
|
|
10
10
|
const hdoc_build_db = require(path.join(__dirname, "hdoc-build-db.js"));
|
|
11
11
|
const hdoc_build_embeddings = require(path.join(__dirname, "hdoc-build-embeddings.js"));
|
|
12
|
-
const hdoc_build_onyx = require(path.join(__dirname, "hdoc-build-onyx.js"));
|
|
13
12
|
const hdoc_build_pdf = require(path.join(__dirname, "hdoc-build-pdf.js"));
|
|
14
13
|
const hdoc_index = require(path.join(__dirname, "hdoc-db.js"));
|
|
15
14
|
const hdoc_mermaid = require(path.join(__dirname, "hdoc-mermaid.js"));
|
|
@@ -49,9 +48,14 @@
|
|
|
49
48
|
"pdf-header-non-git.html",
|
|
50
49
|
);
|
|
51
50
|
|
|
51
|
+
// Mermaid theme — SINGLE source shared with the client-side renderer
|
|
52
|
+
// (ui/js/doc.hornbill.js fetches the same file). Emitted into each queued
|
|
53
|
+
// diagram as YAML frontmatter; inline JSON is valid YAML, so no conversion.
|
|
52
54
|
const mermaid_theme_path = path.resolve(
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
+
__dirname,
|
|
56
|
+
"ui",
|
|
57
|
+
"js",
|
|
58
|
+
"mermaid-theme.json",
|
|
55
59
|
);
|
|
56
60
|
|
|
57
61
|
const pdf_template_path = path.join(__dirname, "templates", "pdf");
|
|
@@ -171,7 +175,8 @@
|
|
|
171
175
|
|
|
172
176
|
let definition = str;
|
|
173
177
|
if (!definition.startsWith('---')) {
|
|
174
|
-
|
|
178
|
+
const theme_json = fs.readFileSync(mermaid_theme_path, {encoding: 'utf-8'});
|
|
179
|
+
definition = `---\nconfig: ${JSON.stringify(JSON.parse(theme_json))}\n---\n${definition}`;
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
// Dedupe identical diagrams (same hash -> same output file).
|
|
@@ -1097,7 +1102,9 @@
|
|
|
1097
1102
|
"hdocbook-project.json",
|
|
1098
1103
|
);
|
|
1099
1104
|
try {
|
|
1100
|
-
hdocbook_project =
|
|
1105
|
+
hdocbook_project = JSON.parse(
|
|
1106
|
+
fs.readFileSync(hdocbook_project_config_path, "utf8"),
|
|
1107
|
+
);
|
|
1101
1108
|
} catch (e) {
|
|
1102
1109
|
console.error("File not found: hdocbook-project.json\n");
|
|
1103
1110
|
console.error(
|
|
@@ -1147,7 +1154,7 @@
|
|
|
1147
1154
|
const work_hdocbook_path = path.join(work_path, doc_id, "hdocbook.json");
|
|
1148
1155
|
|
|
1149
1156
|
try {
|
|
1150
|
-
hdocbook_config =
|
|
1157
|
+
hdocbook_config = JSON.parse(fs.readFileSync(hdocbook_path, "utf8"));
|
|
1151
1158
|
} catch (e) {
|
|
1152
1159
|
console.error(`File not found: ${doc_id}/hdocbook.json\n`);
|
|
1153
1160
|
process.exit(1);
|
|
@@ -1476,6 +1483,7 @@
|
|
|
1476
1483
|
browser,
|
|
1477
1484
|
source_path,
|
|
1478
1485
|
output_links,
|
|
1486
|
+
git_token,
|
|
1479
1487
|
);
|
|
1480
1488
|
|
|
1481
1489
|
// Close the Chromium browser instance
|
package/hdoc-bump.js
CHANGED
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
);
|
|
21
21
|
let hdocbook_project;
|
|
22
22
|
try {
|
|
23
|
-
hdocbook_project =
|
|
23
|
+
hdocbook_project = JSON.parse(
|
|
24
|
+
fs.readFileSync(hdocbook_project_config_path, "utf8"),
|
|
25
|
+
);
|
|
24
26
|
} catch (e) {
|
|
25
27
|
console.error("File not found: hdocbook-project.json:");
|
|
26
28
|
console.error(e, "\n");
|
|
@@ -34,7 +36,7 @@
|
|
|
34
36
|
|
|
35
37
|
let hdocbook_config;
|
|
36
38
|
try {
|
|
37
|
-
hdocbook_config =
|
|
39
|
+
hdocbook_config = JSON.parse(fs.readFileSync(hdocbook_path, "utf8"));
|
|
38
40
|
} catch (e) {
|
|
39
41
|
console.error("File not found: hdocbook.json");
|
|
40
42
|
console.error(e, "\n");
|