hdoc-tools 0.9.40 → 0.9.42

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 CHANGED
@@ -610,23 +610,27 @@
610
610
  if (!validate && hdocbook_project.pdfGeneration !== undefined && hdocbook_project.pdfGeneration.enable !== undefined) {
611
611
  pdf_enable = hdocbook_project.pdfGeneration.enable;
612
612
  }
613
-
613
+
614
614
  console.log(`Loading hdocbook config...`);
615
-
615
+
616
616
  const book_path = path.join(source_path, doc_id),
617
617
  hdocbook_path = path.join(book_path, 'hdocbook.json'),
618
618
  work_path = path.join(source_path, '_work'),
619
619
  work_hdocbook_path = path.join(work_path, doc_id, 'hdocbook.json');
620
620
 
621
621
  hdocbook_config = require(hdocbook_path);
622
- if (build_version !== '') {
623
- hdocbook_config.version = build_version;
622
+ if (build_version !== '') {
623
+ if (build_version.match(regex_version)) {
624
+ hdocbook_config.version = build_version;
625
+ } else {
626
+ console.log(`\n[WARNING] Argument build version [${build_version}] does not match expected pattern, defaulting to version specified in book [${hdocbook_config.version}]\n`);
627
+ }
624
628
  }
625
629
 
626
630
  if (!hdocbook_config.version.match(regex_version)) {
627
631
  console.log(`ERROR: Version number does not match required format - ${hdocbook_config.version}\n`);
628
632
  process.exit(1);
629
- }
633
+ }
630
634
 
631
635
  if (hdocbook_config.publicSource.endsWith('.git')) hdocbook_config.publicSource = hdocbook_config.publicSource.substring(0, hdocbook_config.publicSource.length - 4);
632
636
 
@@ -655,7 +659,7 @@
655
659
  }
656
660
  }
657
661
  }
658
-
662
+
659
663
  console.log(`Building: ${doc_id} v${hdocbook_config.version}...\n`);
660
664
 
661
665
  // Make _work folder to copy everything into
@@ -679,7 +683,7 @@
679
683
 
680
684
  // Create MD5 hash of content before build
681
685
  console.log(`Creating Hash...`);
682
-
686
+
683
687
  dree.scan(work_path_content, md5DreeOptions, hash_callback);
684
688
  let concat_hash = '|';
685
689
  for (let i = 0; i < built_file_hashes.length; i++) {
@@ -731,7 +735,7 @@
731
735
 
732
736
  if (pdf_enable) {
733
737
  // Create a Chromium browser instance generate PDFs with
734
- browser = await puppeteer.launch({headless: 'new'});
738
+ browser = await puppeteer.launch({ headless: 'new' });
735
739
  }
736
740
 
737
741
  // Work through MD files and convert to HTML
@@ -800,7 +804,7 @@
800
804
  if (err) console.log(`Error deleting ${file}: ${e}`);
801
805
  }));
802
806
  }));
803
-
807
+
804
808
  // Add book read timing to the hdocbook.json
805
809
  hdocbook_config.readingTime = Math.ceil(book_read_time + ((book_read_time / 100) * 10));
806
810
  hdocbook_config.navigation.items = hdoc.strip_drafts(hdocbook_config.navigation.items);
@@ -837,7 +841,7 @@
837
841
  console.log(`\nZIP Creation Success: ${zip_path}\n`);
838
842
  console.log(' Build Started:', build_start_dt);
839
843
  console.log(`Build Completed: ${new Date().toLocaleString()}\n`);
840
-
844
+
841
845
  } catch (e) {
842
846
  console.log('\nError creating ZIP: ' + e);
843
847
  }
@@ -848,8 +852,8 @@
848
852
  console.log(`Time Taken: ${get_duration(start_time, end_time)}\n`);
849
853
  };
850
854
 
851
- const get_duration = function(start, end) {
852
- const total_time = new Date(end - start).toISOString().slice(11,19);
855
+ const get_duration = function (start, end) {
856
+ const total_time = new Date(end - start).toISOString().slice(11, 19);
853
857
  const duration_arr = total_time.split(':');
854
858
  let duration = '';
855
859
  if (parseInt(duration_arr[0], 10) > 0) {
package/hdoc-module.js CHANGED
@@ -299,7 +299,8 @@
299
299
  recurse_nav(return_nav);
300
300
  return return_nav;
301
301
  };
302
- const recurse_nav = function(nav_items) {
302
+
303
+ const recurse_nav = function (nav_items) {
303
304
  for (const key in nav_items) {
304
305
  if (nav_items[key].draft) {
305
306
  nav_items.splice(key, 1);
@@ -311,91 +312,42 @@
311
312
  };
312
313
 
313
314
  exports.build_breadcrumbs = function (nav_items) {
314
- let bc = {};
315
- // Steve - need to rework this to use recursion, as it's hard-coded for a maximum of 4 levels deep right now
316
- for (let a = 0; a < nav_items.length; a++) {
317
- const nav_a = nav_items[a];
318
- const parent_a = nav_a.text;
319
- if (nav_a.link) {
320
- bc[nav_a.link] = [{
321
- text: nav_a.text,
322
- link: nav_a.link
323
- }];
315
+ const bc = {};
316
+ const buildBreadcrumb = (items, parentLinks) => {
317
+
318
+ // Process parent links
319
+ let parentlink = true;
320
+ if (parentLinks.length > 0) {
321
+ if (parentLinks[0].link === undefined || parentLinks[0].link === '') parentlink = false;
322
+ if (parentLinks[1] && parentLinks[1].link === undefined && items.length > 0 && items[0].link) {
323
+ parentLinks[1].link = items[0].link;
324
+ }
325
+ if (parentLinks[2] && parentLinks[2].link === undefined && items.length > 0 && items[0].link) {
326
+ parentLinks[2].link = items[0].link;
327
+ }
324
328
  }
325
- if (nav_a.items) {
326
- for (let b = 0; b < nav_a.items.length; b++) {
327
- const nav_b = nav_a.items[b];
328
- const parent_b = nav_b.text;
329
- if (nav_b.link) {
330
- if (bc[nav_a.link]) {
331
- bc[nav_b.link] = bc[nav_a.link];
332
- } else {
333
- bc[nav_b.link] = [{
334
- text: parent_a,
335
- link: nav_a.items[0].link !== undefined ? nav_a.items[0].link : ''
336
- }];
337
- }
338
- bc[nav_b.link].push({
339
- text: nav_b.text,
340
- link: nav_b.link
341
- });
342
- }
343
329
 
344
- if (nav_b.items) {
345
- for (let c = 0; c < nav_b.items.length; c++) {
346
- const nav_c = nav_b.items[c];
347
- const parent_c = nav_c.text;
348
- if (nav_c.link) {
349
- if (bc[nav_b.link]) {
350
- bc[nav_c.link] = bc[nav_b.link];
351
- } else {
352
- bc[nav_c.link] = [{
353
- text: parent_a,
354
- link: nav_a.items[0].link !== undefined ? nav_a.items[0].link : ''
355
- }];
356
- bc[nav_c.link].push({
357
- text: parent_b,
358
- link: nav_b.items[0].link
359
- });
360
- }
361
- bc[nav_c.link].push({
362
- text: nav_c.text,
363
- link: nav_c.link
364
- });
365
- }
330
+ // Loop through items, build breadcrumb
331
+ for (let i = 0; i < items.length; i++) {
332
+ const item = items[i];
333
+ if (!parentlink && item.link) {
334
+ parentLinks[0].link = item.link;
335
+ parentlink = true;
336
+ }
337
+ const { text, link, items: subItems } = item;
338
+ const breadcrumb = [...parentLinks, { text, link }];
366
339
 
367
- if (nav_c.items) {
368
- for (let d = 0; d < nav_c.items.length; d++) {
369
- const nav_d = nav_c.items[d];
370
- if (nav_d.link) {
371
- if (bc[nav_c.link]) {
372
- bc[nav_d.link] = bc[nav_c.link];
373
- } else {
374
- bc[nav_d.link] = [{
375
- text: parent_a,
376
- link: nav_a.items[0].link !== undefined ? nav_a.items[0].link : ''
377
- }];
378
- bc[nav_d.link].push({
379
- text: parent_b,
380
- link: nav_b.items[0].link
381
- });
382
- bc[nav_d.link].push({
383
- text: parent_c,
384
- link: nav_c.items[0].link
385
- });
386
- }
387
- bc[nav_d.link].push({
388
- text: nav_d.text,
389
- link: nav_d.link
390
- });
391
- }
392
- }
393
- }
394
- }
395
- }
340
+ if (link) {
341
+ bc[link] = breadcrumb;
342
+ }
343
+
344
+ if (subItems) {
345
+ buildBreadcrumb(subItems, breadcrumb);
396
346
  }
397
347
  }
398
- }
348
+ };
349
+
350
+ buildBreadcrumb(nav_items, []);
399
351
  return bc;
400
352
  };
401
353
 
@@ -406,7 +358,7 @@
406
358
  prods_supported: [],
407
359
  errors: ''
408
360
  };
409
-
361
+
410
362
  try {
411
363
  const prods = await axios.get('https://docs.hornbill.com/_books/products.json', {
412
364
  httpsAgent: agent
package/hdoc.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  (async function () {
3
3
  'use strict';
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.9.40",
3
+ "version": "0.9.42",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -56,4 +56,4 @@
56
56
  "words-count": "^2.0.2",
57
57
  "zip-a-folder": "^1.1.5"
58
58
  }
59
- }
59
+ }