hdoc-tools 0.8.25 → 0.8.26
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/hdoc-build.js +35 -19
- package/hdoc.js +8 -7
- package/package.json +1 -1
package/hdoc-build.js
CHANGED
@@ -45,7 +45,7 @@
|
|
45
45
|
static_html_files = [],
|
46
46
|
work_path_content = '';
|
47
47
|
|
48
|
-
const transform_static_html = async function (file_path) {
|
48
|
+
const transform_static_html = async function (file_path, verbose, no_pdf) {
|
49
49
|
if (fs.existsSync(file_path.path)) {
|
50
50
|
// Load HTML file
|
51
51
|
let html_txt = fs.readFileSync(file_path.path, 'utf8');
|
@@ -195,11 +195,23 @@
|
|
195
195
|
}
|
196
196
|
|
197
197
|
let doc_header = '';
|
198
|
+
let pdf_header = '';
|
198
199
|
if (hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
|
199
200
|
// Build doc header from template and frontmatter tags
|
200
201
|
doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
|
202
|
+
if (!no_pdf) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
|
201
203
|
} else {
|
202
204
|
doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
|
205
|
+
if (!no_pdf) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
|
206
|
+
}
|
207
|
+
|
208
|
+
if (!no_pdf) {
|
209
|
+
let pdf_txt = await hdoc_build_pdf.process_images(file_path, html_txt);
|
210
|
+
pdf_txt = `${pdf_header}\n${pdf_txt}`;
|
211
|
+
|
212
|
+
// Generate PDF file from HTML
|
213
|
+
const pdf_file_path = file_path.path.replace(path.extname(file_path.path), '.pdf');
|
214
|
+
await hdoc_build_pdf.generate_pdf(pdf_template_path, pdf_template, hdocbook_config, pdf_txt, pdf_file_path, verbose);
|
203
215
|
}
|
204
216
|
|
205
217
|
html_txt = `${fm_header_content}\n${doc_header}\n${html_txt}`;
|
@@ -219,7 +231,7 @@
|
|
219
231
|
}
|
220
232
|
};
|
221
233
|
|
222
|
-
const transform_markdown_and_save_html = async function (file_path, verbose) {
|
234
|
+
const transform_markdown_and_save_html = async function (file_path, verbose, no_pdf) {
|
223
235
|
conversion_attempted++;
|
224
236
|
if (fs.existsSync(file_path.path)) {
|
225
237
|
// Load markdown file
|
@@ -384,19 +396,21 @@
|
|
384
396
|
if (hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
|
385
397
|
// Build doc header from template and frontmatter tags
|
386
398
|
doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
|
387
|
-
pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
|
399
|
+
if (!no_pdf) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
|
388
400
|
} else {
|
389
401
|
// Build doc header from template and frontmatter tags
|
390
402
|
doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
|
391
|
-
pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
|
403
|
+
if (!no_pdf) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
|
392
404
|
}
|
393
405
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
406
|
+
if (!no_pdf) {
|
407
|
+
let pdf_txt = await hdoc_build_pdf.process_images(file_path, html_txt);
|
408
|
+
pdf_txt = `${pdf_header}\n${pdf_txt}`;
|
409
|
+
|
410
|
+
// Generate PDF file from HTML
|
411
|
+
const pdf_file_path = file_path.path.replace(path.extname(file_path.path), '.pdf');
|
412
|
+
await hdoc_build_pdf.generate_pdf(pdf_template_path, pdf_template, hdocbook_config, pdf_txt, pdf_file_path, verbose);
|
413
|
+
}
|
400
414
|
|
401
415
|
html_txt = `${fm_header}\n${doc_header}\n${html_txt}`;
|
402
416
|
|
@@ -618,7 +632,7 @@
|
|
618
632
|
//console.log(JSON.stringify(bc, null, 2));
|
619
633
|
};
|
620
634
|
|
621
|
-
exports.run = async function (source_path, verbose, github_api_token) {
|
635
|
+
exports.run = async function (source_path, verbose, github_api_token, no_pdf) {
|
622
636
|
if (github_api_token !== '') {
|
623
637
|
git_token = github_api_token;
|
624
638
|
}
|
@@ -680,12 +694,14 @@
|
|
680
694
|
process.exit(1);
|
681
695
|
}
|
682
696
|
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
697
|
+
if (!no_pdf) {
|
698
|
+
// Load PDF templates
|
699
|
+
try {
|
700
|
+
pdf_template = fs.readFileSync(pdf_template_file_path, 'utf8');
|
701
|
+
} catch (err) {
|
702
|
+
console.log(`Error reading PDF template: ${err}`);
|
703
|
+
process.exit(1);
|
704
|
+
}
|
689
705
|
}
|
690
706
|
|
691
707
|
build_breadcrumbs(hdocbook_config.navigation.items);
|
@@ -696,12 +712,12 @@
|
|
696
712
|
|
697
713
|
// Work through MD files and convert to HTML
|
698
714
|
for (let i = 0; i < md_files.length; i++) {
|
699
|
-
await transform_markdown_and_save_html(md_files[i], verbose);
|
715
|
+
await transform_markdown_and_save_html(md_files[i], verbose, no_pdf);
|
700
716
|
}
|
701
717
|
|
702
718
|
// Work through Static HTML files and add Frontmatter tags
|
703
719
|
for (let i = 0; i < static_html_files.length; i++) {
|
704
|
-
await transform_static_html(static_html_files[i]);
|
720
|
+
await transform_static_html(static_html_files[i], verbose, no_pdf);
|
705
721
|
}
|
706
722
|
|
707
723
|
// Output to console
|
package/hdoc.js
CHANGED
@@ -27,7 +27,8 @@
|
|
27
27
|
let ui_path = path.join(__dirname, 'ui');
|
28
28
|
let git_token = '';
|
29
29
|
let command = '', // Our command to run
|
30
|
-
verbose = false
|
30
|
+
verbose = false,
|
31
|
+
no_pdf = false;
|
31
32
|
|
32
33
|
// Get options from command args
|
33
34
|
for (let x = 0; x < process.argv.length; x++) {
|
@@ -40,7 +41,11 @@
|
|
40
41
|
continue;
|
41
42
|
}
|
42
43
|
|
43
|
-
if (process.argv[x]
|
44
|
+
if (process.argv[x] === '-v') {
|
45
|
+
verbose = true;
|
46
|
+
} else if (process.argv[x] === '-no-pdf') {
|
47
|
+
no_pdf = true;
|
48
|
+
} else if (process.argv[x] == '-path') {
|
44
49
|
x++;
|
45
50
|
if (x < process.argv.length) {
|
46
51
|
source_path = process.argv[x];
|
@@ -56,10 +61,6 @@
|
|
56
61
|
git_token = process.argv[x];
|
57
62
|
}
|
58
63
|
}
|
59
|
-
|
60
|
-
if (process.argv[x] === '-v') {
|
61
|
-
verbose = true;
|
62
|
-
}
|
63
64
|
}
|
64
65
|
|
65
66
|
console.log('Hornbill HDocBook Tools v' + getHdocPackageVersion(packageFile), '\r\n');
|
@@ -71,7 +72,7 @@
|
|
71
72
|
server.run(ui_path, source_path);
|
72
73
|
} else if (command == 'build') {
|
73
74
|
const builder = require(path.join(__dirname, 'hdoc-build.js'));
|
74
|
-
await builder.run(source_path, verbose, git_token);
|
75
|
+
await builder.run(source_path, verbose, git_token, no_pdf);
|
75
76
|
} else if (command == 'stats') {
|
76
77
|
const stats = require(path.join(__dirname, 'hdoc-stats.js'));
|
77
78
|
stats.run(ui_path, source_path, verbose);
|