hdoc-tools 0.15.1 → 0.15.2

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 (2) hide show
  1. package/hdoc-build.js +31 -17
  2. package/package.json +1 -1
package/hdoc-build.js CHANGED
@@ -24,7 +24,8 @@
24
24
  non_git_pdf_header_template_path = path.join(__dirname, 'templates', 'pdf-header-non-git.html'),
25
25
  pdf_template_path = path.join(__dirname, 'templates', 'pdf'),
26
26
  pdf_template_file_path = path.join(pdf_template_path, 'template.html'),
27
- regex_version = /^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,6}$/;
27
+ regex_version = /^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,6}$/,
28
+ h1_pattern = /(<h1.*?>)\s*.*\s*(.*<\/h1>)/;
28
29
 
29
30
  let bc = {}, // Breadcrumbs map
30
31
  built_file_hashes = [],
@@ -126,7 +127,7 @@
126
127
  }
127
128
  }
128
129
 
129
- if (!fm_title_found) {
130
+ if (!fm_title_found && file_path.name !== 'description_ext.md' && file_path.name !== 'article_ext.md') {
130
131
  // No frontmatter title found in properties
131
132
  // Go get title from h tags in html
132
133
  const html_heading = hdoc.getFirstHTMLHeading(html_txt, h_tags_to_search);
@@ -153,7 +154,7 @@
153
154
  id: 'title',
154
155
  value: html_heading[0].children[0].data
155
156
  });
156
- } else {
157
+ } else if (file_path.name !== 'description_ext.md' && file_path.name !== 'article_ext.md') {
157
158
  // No header tag, no frontmatter title, output a warning
158
159
  console.log(`[WARNING] No frontmatter title property, or ${h_tags_to_search.join(', ')} tags detected in ${file_path.path}`);
159
160
  }
@@ -176,7 +177,11 @@
176
177
  let metadata = {};
177
178
 
178
179
  // Remove the first <h1>title</h1> from the HTML as we'll add that in the document header
179
- html_txt = html_txt.replace(/(<h1.*?>)\s*.*\s*(.*<\/h1>)/, '');
180
+ let html_h1 = h1_pattern.exec(html_txt);
181
+ if (html_h1 && html_h1[0])
182
+ html_h1 = html_h1[0].replace(/(<h1.*?>)/, '').replace(/(<\/h1>)/, '');
183
+
184
+ html_txt = html_txt.replace(h1_pattern, '');
180
185
 
181
186
  // Get contributor data from Github, if exists
182
187
  let contribs = [];
@@ -240,16 +245,16 @@
240
245
  if (hdocbook_config.publicSource && hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
241
246
  // Build doc header from template and frontmatter tags
242
247
  if (!inline_content)
243
- doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
248
+ doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template, html_h1);
244
249
 
245
250
  if (pdf_enable && !pdf_path_excluded(file_path.relativePath))
246
- pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
251
+ pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template, html_h1);
247
252
  } else {
248
253
  if (!inline_content)
249
- doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
254
+ doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git, html_h1);
250
255
 
251
256
  if (pdf_enable && !pdf_path_excluded(file_path.relativePath))
252
- pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
257
+ pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git, html_h1);
253
258
  }
254
259
 
255
260
  let pdf_size = 0;
@@ -388,7 +393,7 @@
388
393
  value: html_heading[0].children[0].data.trim()
389
394
  });
390
395
  doc_title = html_heading[0].children[0].data.trim();
391
- } else {
396
+ } else if (file_path.name !== 'description_ext.md' && file_path.name !== 'article_ext.md') {
392
397
  // No header tag, no frontmatter title, output a warning
393
398
  console.log(`[WARNING] No frontmatter title property, or h1, h2 or h3 header tags detected in ${file_path.path}`);
394
399
  }
@@ -406,7 +411,11 @@
406
411
  let metadata = {};
407
412
 
408
413
  // Remove the first <h1>title</h1> from the HTML as we'll add that in the document header
409
- html_txt = html_txt.replace(/(<h1.*?>)\s*.*\s*(.*<\/h1>)/, '');
414
+ let html_h1 = h1_pattern.exec(html_txt);
415
+ if (html_h1 && html_h1[0])
416
+ html_h1 = html_h1[0].replace(/(<h1.*?>)/, '').replace(/(<\/h1>)/, '');
417
+
418
+ html_txt = html_txt.replace(h1_pattern, '');
410
419
 
411
420
  // Get contributor data from Github, if exists
412
421
  let contribs = [];
@@ -472,17 +481,17 @@
472
481
  if (hdocbook_config.publicSource && hdocbook_config.publicSource.includes('github.com/Hornbill-Docs')) {
473
482
  // Build doc header from template and frontmatter tags
474
483
  if (!inline_content)
475
- doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template);
484
+ doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template, html_h1);
476
485
 
477
486
  if (pdf_enable && !pdf_path_excluded(file_path.relativePath))
478
- pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template);
487
+ pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template, html_h1);
479
488
  } else {
480
489
  // Build doc header from template and frontmatter tags
481
490
  if (!inline_content)
482
- doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git);
491
+ doc_header = process_doc_header(fm_headers, file_path.relativePath, doc_header_template_non_git, html_h1);
483
492
 
484
493
  if (pdf_enable && !pdf_path_excluded(file_path.relativePath))
485
- pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git);
494
+ pdf_header = process_doc_header(fm_headers, file_path.relativePath, pdf_header_template_non_git, html_h1);
486
495
  }
487
496
 
488
497
  let pdf_size = 0;
@@ -532,14 +541,19 @@
532
541
  return false;
533
542
  };
534
543
 
535
- const process_doc_header = function (fm_headers, doc_path, template) {
544
+ const process_doc_header = function (fm_headers, doc_path, template, h1) {
536
545
  let wip_doc_header = template;
537
-
546
+ let used_h1 = false;
547
+ if (h1 && h1 !== '') {
548
+ wip_doc_header = wip_doc_header.replaceAll('{{title}}', h1);
549
+ used_h1 = true;
550
+ }
538
551
  // Process fm_headers properties first
539
552
  for (let i = 0; i < fm_headers.length; i++) {
540
553
  switch (fm_headers[i].id) {
541
554
  case 'title':
542
- wip_doc_header = wip_doc_header.replaceAll('{{title}}', fm_headers[i].value);
555
+ if (!used_h1)
556
+ wip_doc_header = wip_doc_header.replaceAll('{{title}}', fm_headers[i].value);
543
557
  break;
544
558
  case 'reading-time':
545
559
  wip_doc_header = wip_doc_header.replaceAll('{{reading-time}}', fm_headers[i].value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.15.1",
3
+ "version": "0.15.2",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {