hdoc-tools 0.8.25 → 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 +69 -25
  2. package/hdoc.js +3 -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,7 +44,24 @@
43
44
  index_records = [],
44
45
  md_files = [],
45
46
  static_html_files = [],
46
- work_path_content = '';
47
+ work_path_content = '',
48
+ verbose = false;
49
+
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
+ };
47
65
 
48
66
  const transform_static_html = async function (file_path) {
49
67
  if (fs.existsSync(file_path.path)) {
@@ -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);
@@ -195,11 +214,23 @@
195
214
  }
196
215
 
197
216
  let doc_header = '';
217
+ let pdf_header = '';
198
218
  if (hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
199
219
  // Build doc header from template and frontmatter tags
200
220
  doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_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);
201
222
  } else {
202
223
  doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_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);
225
+ }
226
+
227
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) {
228
+ let pdf_txt = await hdoc_build_pdf.process_images(file_path, html_txt);
229
+ pdf_txt = `${pdf_header}\n${pdf_txt}`;
230
+
231
+ // Generate PDF file from HTML
232
+ const pdf_file_path = file_path.path.replace(path.extname(file_path.path), '.pdf');
233
+ await hdoc_build_pdf.generate_pdf(pdf_template_path, pdf_template, hdocbook_config, pdf_txt, pdf_file_path, verbose);
203
234
  }
204
235
 
205
236
  html_txt = `${fm_header_content}\n${doc_header}\n${html_txt}`;
@@ -219,7 +250,7 @@
219
250
  }
220
251
  };
221
252
 
222
- const transform_markdown_and_save_html = async function (file_path, verbose) {
253
+ const transform_markdown_and_save_html = async function (file_path) {
223
254
  conversion_attempted++;
224
255
  if (fs.existsSync(file_path.path)) {
225
256
  // Load markdown file
@@ -328,11 +359,12 @@
328
359
  }
329
360
  let metadata = {};
330
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
+
331
365
  // Get contributor data from Github, if exists
332
366
  let contribs = [];
333
367
  if (hdocbook_config.publicSource && hdocbook_config.publicSource !== '' && hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
334
- // Remove the first <h1>title</h1> from the HTML as we'll add that in the document header
335
- html_txt = html_txt.replace(/(<h1.*?>)\s*.*\s*(.*<\/h1>)/, '');
336
368
 
337
369
  const github_paths = hdoc.get_github_api_path(hdocbook_config.publicSource, file_path.relativePath);
338
370
  const contributors = hdoc.get_github_contributors(github_paths.api_path, git_token);
@@ -384,19 +416,21 @@
384
416
  if (hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
385
417
  // Build doc header from template and frontmatter tags
386
418
  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);
419
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
388
420
  } else {
389
421
  // Build doc header from template and frontmatter tags
390
422
  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);
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);
392
424
  }
393
425
 
394
- let pdf_txt = await hdoc_build_pdf.process_images(file_path, html_txt);
395
- pdf_txt = `${pdf_header}\n${pdf_txt}`;
396
-
397
- // Generate PDF file from HTML
398
- const pdf_file_path = file_path.path.replace(path.extname(file_path.path), '.pdf');
399
- await hdoc_build_pdf.generate_pdf(pdf_template_path, pdf_template, hdocbook_config, pdf_txt, pdf_file_path, verbose);
426
+ if (pdf_enable && !pdf_path_excluded(file_path.relativePath)) {
427
+ let pdf_txt = await hdoc_build_pdf.process_images(file_path, html_txt);
428
+ pdf_txt = `${pdf_header}\n${pdf_txt}`;
429
+
430
+ // Generate PDF file from HTML
431
+ const pdf_file_path = file_path.path.replace(path.extname(file_path.path), '.pdf');
432
+ await hdoc_build_pdf.generate_pdf(pdf_template_path, pdf_template, hdocbook_config, pdf_txt, pdf_file_path, verbose);
433
+ }
400
434
 
401
435
  html_txt = `${fm_header}\n${doc_header}\n${html_txt}`;
402
436
 
@@ -469,7 +503,9 @@
469
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`;
470
504
  }
471
505
  } else {
472
- 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
+ }
473
509
  }
474
510
  bc_tags += '\t\t\t';
475
511
  wip_doc_header = wip_doc_header.replaceAll('{{breadcrumbs}}', bc_tags);
@@ -618,11 +654,11 @@
618
654
  //console.log(JSON.stringify(bc, null, 2));
619
655
  };
620
656
 
621
- exports.run = async function (source_path, verbose, github_api_token) {
657
+ exports.run = async function (source_path, verbose_output, github_api_token) {
622
658
  if (github_api_token !== '') {
623
659
  git_token = github_api_token;
624
660
  }
625
-
661
+ verbose = verbose_output;
626
662
  // GERRY: The purpose of this function is to create a zip file containing the hdocbook content,
627
663
  // * Create a _work folder
628
664
  // * copy the hdocbook content to the work folder
@@ -635,12 +671,16 @@
635
671
 
636
672
  console.log('Hornbill HDocBook Build', '\n');
637
673
  console.log(' Document Path:', source_path, '\n');
674
+ const build_start_dt = new Date().toLocaleString();
638
675
 
639
676
  // Load the hdocbook-project.json file to get the docId
640
677
  // use the docId to get the book config
641
678
  const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
642
679
  hdocbook_project = require(hdocbook_project_config_path);
643
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
+ }
644
684
 
645
685
  const book_path = path.join(source_path, doc_id),
646
686
  hdocbook_path = path.join(book_path, 'hdocbook.json'),
@@ -680,12 +720,14 @@
680
720
  process.exit(1);
681
721
  }
682
722
 
683
- // Load PDF templates
684
- try {
685
- pdf_template = fs.readFileSync(pdf_template_file_path, 'utf8');
686
- } catch (err) {
687
- console.log(`Error reading PDF template: ${err}`);
688
- process.exit(1);
723
+ if (pdf_enable) {
724
+ // Load PDF templates
725
+ try {
726
+ pdf_template = fs.readFileSync(pdf_template_file_path, 'utf8');
727
+ } catch (err) {
728
+ console.log(`Error reading PDF template: ${err}`);
729
+ process.exit(1);
730
+ }
689
731
  }
690
732
 
691
733
  build_breadcrumbs(hdocbook_config.navigation.items);
@@ -696,7 +738,7 @@
696
738
 
697
739
  // Work through MD files and convert to HTML
698
740
  for (let i = 0; i < md_files.length; i++) {
699
- await transform_markdown_and_save_html(md_files[i], verbose);
741
+ await transform_markdown_and_save_html(md_files[i]);
700
742
  }
701
743
 
702
744
  // Work through Static HTML files and add Frontmatter tags
@@ -769,7 +811,9 @@
769
811
  const zip_path = path.join(work_path, doc_id + '.zip');
770
812
  zipper.sync.zip(work_path_content).compress().save(zip_path);
771
813
  console.log(`\nZIP Creation Success: ${zip_path}\n`);
772
- console.log('Build Complete\n');
814
+ console.log(' Build Started:', build_start_dt);
815
+ console.log(`Build Completed: ${new Date().toLocaleString()}\n`);
816
+
773
817
  } catch (e) {
774
818
  console.log('\nError creating ZIP: ' + e);
775
819
  }
package/hdoc.js CHANGED
@@ -40,7 +40,9 @@
40
40
  continue;
41
41
  }
42
42
 
43
- if (process.argv[x] == '-path') {
43
+ if (process.argv[x] === '-v') {
44
+ verbose = true;
45
+ } else if (process.argv[x] == '-path') {
44
46
  x++;
45
47
  if (x < process.argv.length) {
46
48
  source_path = process.argv[x];
@@ -56,10 +58,6 @@
56
58
  git_token = process.argv[x];
57
59
  }
58
60
  }
59
-
60
- if (process.argv[x] === '-v') {
61
- verbose = true;
62
- }
63
61
  }
64
62
 
65
63
  console.log('Hornbill HDocBook Tools v' + getHdocPackageVersion(packageFile), '\r\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.8.25",
3
+ "version": "0.8.27",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {