hdoc-tools 0.8.26 → 0.8.27

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.
Files changed (3) hide show
  1. package/hdoc-build.js +48 -20
  2. package/hdoc.js +2 -5
  3. 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,26 @@
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 transform_static_html = async function (file_path, verbose, no_pdf) {
50
+ const pdf_path_excluded = function(relative_path) {
51
+ if (relative_path.startsWith('/')) {
52
+ relative_path = relative_path.slice(1, relative_path.length);
53
+ }
54
+ for (let i = 0; i < hdocbook_project.pdfGeneration.exclude_paths.length; i++) {
55
+ const exclude_path = hdocbook_project.pdfGeneration.exclude_paths[i];
56
+ if (relative_path === exclude_path) return true;
57
+ if (exclude_path.at(-1) === '*') {
58
+ if (relative_path.startsWith(exclude_path.slice(0, -1))) {
59
+ return true;
60
+ }
61
+ }
62
+ }
63
+ return false;
64
+ };
65
+
66
+ const transform_static_html = async function (file_path) {
49
67
  if (fs.existsSync(file_path.path)) {
50
68
  // Load HTML file
51
69
  let html_txt = fs.readFileSync(file_path.path, 'utf8');
@@ -141,11 +159,12 @@
141
159
 
142
160
  let metadata = {};
143
161
 
162
+ // Remove the first <h1>title</h1> from the HTML as we'll add that in the document header
163
+ html_txt = html_txt.replace(/(<h1.*?>)\s*.*\s*(.*<\/h1>)/, '');
164
+
144
165
  // Get contributor data from Github, if exists
145
166
  let contribs = [];
146
167
  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
168
 
150
169
  const github_paths = hdoc.get_github_api_path(hdocbook_config.publicSource, file_path.relativePath);
151
170
  const contributors = hdoc.get_github_contributors(github_paths.api_path, git_token);
@@ -199,13 +218,13 @@
199
218
  if (hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
200
219
  // Build doc header from template and frontmatter tags
201
220
  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);
221
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
203
222
  } else {
204
223
  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);
224
+ 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
225
  }
207
226
 
208
- if (!no_pdf) {
227
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) {
209
228
  let pdf_txt = await hdoc_build_pdf.process_images(file_path, html_txt);
210
229
  pdf_txt = `${pdf_header}\n${pdf_txt}`;
211
230
 
@@ -231,7 +250,7 @@
231
250
  }
232
251
  };
233
252
 
234
- const transform_markdown_and_save_html = async function (file_path, verbose, no_pdf) {
253
+ const transform_markdown_and_save_html = async function (file_path) {
235
254
  conversion_attempted++;
236
255
  if (fs.existsSync(file_path.path)) {
237
256
  // Load markdown file
@@ -340,11 +359,12 @@
340
359
  }
341
360
  let metadata = {};
342
361
 
362
+ // Remove the first <h1>title</h1> from the HTML as we'll add that in the document header
363
+ html_txt = html_txt.replace(/(<h1.*?>)\s*.*\s*(.*<\/h1>)/, '');
364
+
343
365
  // Get contributor data from Github, if exists
344
366
  let contribs = [];
345
367
  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
368
 
349
369
  const github_paths = hdoc.get_github_api_path(hdocbook_config.publicSource, file_path.relativePath);
350
370
  const contributors = hdoc.get_github_contributors(github_paths.api_path, git_token);
@@ -396,14 +416,14 @@
396
416
  if (hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
397
417
  // Build doc header from template and frontmatter tags
398
418
  doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
399
- if (!no_pdf) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
419
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
400
420
  } else {
401
421
  // Build doc header from template and frontmatter tags
402
422
  doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
403
- if (!no_pdf) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
423
+ 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
424
  }
405
425
 
406
- if (!no_pdf) {
426
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) {
407
427
  let pdf_txt = await hdoc_build_pdf.process_images(file_path, html_txt);
408
428
  pdf_txt = `${pdf_header}\n${pdf_txt}`;
409
429
 
@@ -483,7 +503,9 @@
483
503
  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
504
  }
485
505
  } else {
486
- console.log(`[WARNING] Path is not present in navigation items: ${logical_path}`);
506
+ if (verbose) {
507
+ console.log(`[WARNING] Path is not present in navigation items: ${logical_path}`);
508
+ }
487
509
  }
488
510
  bc_tags += '\t\t\t';
489
511
  wip_doc_header = wip_doc_header.replaceAll('{{breadcrumbs}}', bc_tags);
@@ -632,11 +654,11 @@
632
654
  //console.log(JSON.stringify(bc, null, 2));
633
655
  };
634
656
 
635
- exports.run = async function (source_path, verbose, github_api_token, no_pdf) {
657
+ exports.run = async function (source_path, verbose_output, github_api_token) {
636
658
  if (github_api_token !== '') {
637
659
  git_token = github_api_token;
638
660
  }
639
-
661
+ verbose = verbose_output;
640
662
  // GERRY: The purpose of this function is to create a zip file containing the hdocbook content,
641
663
  // * Create a _work folder
642
664
  // * copy the hdocbook content to the work folder
@@ -649,12 +671,16 @@
649
671
 
650
672
  console.log('Hornbill HDocBook Build', '\n');
651
673
  console.log(' Document Path:', source_path, '\n');
674
+ const build_start_dt = new Date().toLocaleString();
652
675
 
653
676
  // Load the hdocbook-project.json file to get the docId
654
677
  // use the docId to get the book config
655
678
  const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
656
679
  hdocbook_project = require(hdocbook_project_config_path);
657
680
  doc_id = hdocbook_project.docId;
681
+ if (hdocbook_project.pdfGeneration !== undefined && hdocbook_project.pdfGeneration.enable !== undefined) {
682
+ pdf_enable = hdocbook_project.pdfGeneration.enable;
683
+ }
658
684
 
659
685
  const book_path = path.join(source_path, doc_id),
660
686
  hdocbook_path = path.join(book_path, 'hdocbook.json'),
@@ -694,7 +720,7 @@
694
720
  process.exit(1);
695
721
  }
696
722
 
697
- if (!no_pdf) {
723
+ if (pdf_enable) {
698
724
  // Load PDF templates
699
725
  try {
700
726
  pdf_template = fs.readFileSync(pdf_template_file_path, 'utf8');
@@ -712,12 +738,12 @@
712
738
 
713
739
  // Work through MD files and convert to HTML
714
740
  for (let i = 0; i < md_files.length; i++) {
715
- await transform_markdown_and_save_html(md_files[i], verbose, no_pdf);
741
+ await transform_markdown_and_save_html(md_files[i]);
716
742
  }
717
743
 
718
744
  // Work through Static HTML files and add Frontmatter tags
719
745
  for (let i = 0; i < static_html_files.length; i++) {
720
- await transform_static_html(static_html_files[i], verbose, no_pdf);
746
+ await transform_static_html(static_html_files[i]);
721
747
  }
722
748
 
723
749
  // Output to console
@@ -785,7 +811,9 @@
785
811
  const zip_path = path.join(work_path, doc_id + '.zip');
786
812
  zipper.sync.zip(work_path_content).compress().save(zip_path);
787
813
  console.log(`\nZIP Creation Success: ${zip_path}\n`);
788
- console.log('Build Complete\n');
814
+ console.log(' Build Started:', build_start_dt);
815
+ console.log(`Build Completed: ${new Date().toLocaleString()}\n`);
816
+
789
817
  } catch (e) {
790
818
  console.log('\nError creating ZIP: ' + e);
791
819
  }
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, no_pdf);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.8.26",
3
+ "version": "0.8.27",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {