hdoc-tools 0.8.26 → 0.8.28
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 +51 -20
- package/hdoc.js +2 -5
- package/package.json +1 -1
package/hdoc-build.js
CHANGED
@@ -30,6 +30,7 @@
|
|
30
30
|
conversion_failed = 0,
|
31
31
|
doc_header_template = '',
|
32
32
|
doc_header_template_non_git = '',
|
33
|
+
pdf_enable = false,
|
33
34
|
pdf_header_template = '',
|
34
35
|
pdf_header_template_non_git = '',
|
35
36
|
pdf_template = '',
|
@@ -43,9 +44,29 @@
|
|
43
44
|
index_records = [],
|
44
45
|
md_files = [],
|
45
46
|
static_html_files = [],
|
46
|
-
work_path_content = ''
|
47
|
+
work_path_content = '',
|
48
|
+
verbose = false;
|
47
49
|
|
48
|
-
const
|
50
|
+
const pdf_path_excluded = function(relative_path) {
|
51
|
+
if (!hdocbook_project.pdfGeneration || hdocbook_project.pdfGeneration.exclude_paths === undefined) {
|
52
|
+
return false;
|
53
|
+
}
|
54
|
+
if (relative_path.startsWith('/')) {
|
55
|
+
relative_path = relative_path.slice(1, relative_path.length);
|
56
|
+
}
|
57
|
+
for (let i = 0; i < hdocbook_project.pdfGeneration.exclude_paths.length; i++) {
|
58
|
+
const exclude_path = hdocbook_project.pdfGeneration.exclude_paths[i];
|
59
|
+
if (relative_path === exclude_path) return true;
|
60
|
+
if (exclude_path.at(-1) === '*') {
|
61
|
+
if (relative_path.startsWith(exclude_path.slice(0, -1))) {
|
62
|
+
return true;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return false;
|
67
|
+
};
|
68
|
+
|
69
|
+
const transform_static_html = async function (file_path) {
|
49
70
|
if (fs.existsSync(file_path.path)) {
|
50
71
|
// Load HTML file
|
51
72
|
let html_txt = fs.readFileSync(file_path.path, 'utf8');
|
@@ -141,11 +162,12 @@
|
|
141
162
|
|
142
163
|
let metadata = {};
|
143
164
|
|
165
|
+
// Remove the first <h1>title</h1> from the HTML as we'll add that in the document header
|
166
|
+
html_txt = html_txt.replace(/(<h1.*?>)\s*.*\s*(.*<\/h1>)/, '');
|
167
|
+
|
144
168
|
// Get contributor data from Github, if exists
|
145
169
|
let contribs = [];
|
146
170
|
if (hdocbook_config.publicSource && hdocbook_config.publicSource !== '' && hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
|
147
|
-
// Remove the first <h1>title</h1> from the HTML as we'll add that in the document header
|
148
|
-
html_txt = html_txt.replace(/(<h1.*?>)\s*.*\s*(.*<\/h1>)/, '');
|
149
171
|
|
150
172
|
const github_paths = hdoc.get_github_api_path(hdocbook_config.publicSource, file_path.relativePath);
|
151
173
|
const contributors = hdoc.get_github_contributors(github_paths.api_path, git_token);
|
@@ -199,13 +221,13 @@
|
|
199
221
|
if (hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
|
200
222
|
// Build doc header from template and frontmatter tags
|
201
223
|
doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
|
202
|
-
if (!
|
224
|
+
if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
|
203
225
|
} else {
|
204
226
|
doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
|
205
|
-
if (!
|
227
|
+
if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
|
206
228
|
}
|
207
229
|
|
208
|
-
if (!
|
230
|
+
if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) {
|
209
231
|
let pdf_txt = await hdoc_build_pdf.process_images(file_path, html_txt);
|
210
232
|
pdf_txt = `${pdf_header}\n${pdf_txt}`;
|
211
233
|
|
@@ -231,7 +253,7 @@
|
|
231
253
|
}
|
232
254
|
};
|
233
255
|
|
234
|
-
const transform_markdown_and_save_html = async function (file_path
|
256
|
+
const transform_markdown_and_save_html = async function (file_path) {
|
235
257
|
conversion_attempted++;
|
236
258
|
if (fs.existsSync(file_path.path)) {
|
237
259
|
// Load markdown file
|
@@ -340,11 +362,12 @@
|
|
340
362
|
}
|
341
363
|
let metadata = {};
|
342
364
|
|
365
|
+
// Remove the first <h1>title</h1> from the HTML as we'll add that in the document header
|
366
|
+
html_txt = html_txt.replace(/(<h1.*?>)\s*.*\s*(.*<\/h1>)/, '');
|
367
|
+
|
343
368
|
// Get contributor data from Github, if exists
|
344
369
|
let contribs = [];
|
345
370
|
if (hdocbook_config.publicSource && hdocbook_config.publicSource !== '' && hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
|
346
|
-
// Remove the first <h1>title</h1> from the HTML as we'll add that in the document header
|
347
|
-
html_txt = html_txt.replace(/(<h1.*?>)\s*.*\s*(.*<\/h1>)/, '');
|
348
371
|
|
349
372
|
const github_paths = hdoc.get_github_api_path(hdocbook_config.publicSource, file_path.relativePath);
|
350
373
|
const contributors = hdoc.get_github_contributors(github_paths.api_path, git_token);
|
@@ -396,14 +419,14 @@
|
|
396
419
|
if (hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
|
397
420
|
// Build doc header from template and frontmatter tags
|
398
421
|
doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
|
399
|
-
if (!
|
422
|
+
if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
|
400
423
|
} else {
|
401
424
|
// Build doc header from template and frontmatter tags
|
402
425
|
doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
|
403
|
-
if (!
|
426
|
+
if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
|
404
427
|
}
|
405
428
|
|
406
|
-
if (!
|
429
|
+
if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) {
|
407
430
|
let pdf_txt = await hdoc_build_pdf.process_images(file_path, html_txt);
|
408
431
|
pdf_txt = `${pdf_header}\n${pdf_txt}`;
|
409
432
|
|
@@ -483,7 +506,9 @@
|
|
483
506
|
bc_tags += `\t\t\t\t<li class="mt-0 nav-bar-item"><a href="${bc_for_path[i].link}" class="ps-0 pe-0 text-decoration-none">${bc_for_path[i].text}</a></li>\n`;
|
484
507
|
}
|
485
508
|
} else {
|
486
|
-
|
509
|
+
if (verbose) {
|
510
|
+
console.log(`[WARNING] Path is not present in navigation items: ${logical_path}`);
|
511
|
+
}
|
487
512
|
}
|
488
513
|
bc_tags += '\t\t\t';
|
489
514
|
wip_doc_header = wip_doc_header.replaceAll('{{breadcrumbs}}', bc_tags);
|
@@ -632,11 +657,11 @@
|
|
632
657
|
//console.log(JSON.stringify(bc, null, 2));
|
633
658
|
};
|
634
659
|
|
635
|
-
exports.run = async function (source_path,
|
660
|
+
exports.run = async function (source_path, verbose_output, github_api_token) {
|
636
661
|
if (github_api_token !== '') {
|
637
662
|
git_token = github_api_token;
|
638
663
|
}
|
639
|
-
|
664
|
+
verbose = verbose_output;
|
640
665
|
// GERRY: The purpose of this function is to create a zip file containing the hdocbook content,
|
641
666
|
// * Create a _work folder
|
642
667
|
// * copy the hdocbook content to the work folder
|
@@ -649,12 +674,16 @@
|
|
649
674
|
|
650
675
|
console.log('Hornbill HDocBook Build', '\n');
|
651
676
|
console.log(' Document Path:', source_path, '\n');
|
677
|
+
const build_start_dt = new Date().toLocaleString();
|
652
678
|
|
653
679
|
// Load the hdocbook-project.json file to get the docId
|
654
680
|
// use the docId to get the book config
|
655
681
|
const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
|
656
682
|
hdocbook_project = require(hdocbook_project_config_path);
|
657
683
|
doc_id = hdocbook_project.docId;
|
684
|
+
if (hdocbook_project.pdfGeneration !== undefined && hdocbook_project.pdfGeneration.enable !== undefined) {
|
685
|
+
pdf_enable = hdocbook_project.pdfGeneration.enable;
|
686
|
+
}
|
658
687
|
|
659
688
|
const book_path = path.join(source_path, doc_id),
|
660
689
|
hdocbook_path = path.join(book_path, 'hdocbook.json'),
|
@@ -694,7 +723,7 @@
|
|
694
723
|
process.exit(1);
|
695
724
|
}
|
696
725
|
|
697
|
-
if (
|
726
|
+
if (pdf_enable) {
|
698
727
|
// Load PDF templates
|
699
728
|
try {
|
700
729
|
pdf_template = fs.readFileSync(pdf_template_file_path, 'utf8');
|
@@ -712,12 +741,12 @@
|
|
712
741
|
|
713
742
|
// Work through MD files and convert to HTML
|
714
743
|
for (let i = 0; i < md_files.length; i++) {
|
715
|
-
await transform_markdown_and_save_html(md_files[i]
|
744
|
+
await transform_markdown_and_save_html(md_files[i]);
|
716
745
|
}
|
717
746
|
|
718
747
|
// Work through Static HTML files and add Frontmatter tags
|
719
748
|
for (let i = 0; i < static_html_files.length; i++) {
|
720
|
-
await transform_static_html(static_html_files[i]
|
749
|
+
await transform_static_html(static_html_files[i]);
|
721
750
|
}
|
722
751
|
|
723
752
|
// Output to console
|
@@ -785,7 +814,9 @@
|
|
785
814
|
const zip_path = path.join(work_path, doc_id + '.zip');
|
786
815
|
zipper.sync.zip(work_path_content).compress().save(zip_path);
|
787
816
|
console.log(`\nZIP Creation Success: ${zip_path}\n`);
|
788
|
-
console.log('Build
|
817
|
+
console.log(' Build Started:', build_start_dt);
|
818
|
+
console.log(`Build Completed: ${new Date().toLocaleString()}\n`);
|
819
|
+
|
789
820
|
} catch (e) {
|
790
821
|
console.log('\nError creating ZIP: ' + e);
|
791
822
|
}
|
package/hdoc.js
CHANGED
@@ -27,8 +27,7 @@
|
|
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
|
31
|
-
no_pdf = false;
|
30
|
+
verbose = false;
|
32
31
|
|
33
32
|
// Get options from command args
|
34
33
|
for (let x = 0; x < process.argv.length; x++) {
|
@@ -43,8 +42,6 @@
|
|
43
42
|
|
44
43
|
if (process.argv[x] === '-v') {
|
45
44
|
verbose = true;
|
46
|
-
} else if (process.argv[x] === '-no-pdf') {
|
47
|
-
no_pdf = true;
|
48
45
|
} else if (process.argv[x] == '-path') {
|
49
46
|
x++;
|
50
47
|
if (x < process.argv.length) {
|
@@ -72,7 +69,7 @@
|
|
72
69
|
server.run(ui_path, source_path);
|
73
70
|
} else if (command == 'build') {
|
74
71
|
const builder = require(path.join(__dirname, 'hdoc-build.js'));
|
75
|
-
await builder.run(source_path, verbose, git_token
|
72
|
+
await builder.run(source_path, verbose, git_token);
|
76
73
|
} else if (command == 'stats') {
|
77
74
|
const stats = require(path.join(__dirname, 'hdoc-stats.js'));
|
78
75
|
stats.run(ui_path, source_path, verbose);
|