hdoc-tools 0.9.11 → 0.9.13

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/README.md CHANGED
@@ -18,6 +18,10 @@ Outputs available arguments and switches.
18
18
 
19
19
  Initializes a new HDocBook project from a template, using runtime input variables.
20
20
 
21
+ ### createDocs
22
+
23
+ Creates folder structure and markdown documents as defined in the HDocBook navigation item links
24
+
21
25
  ### stats
22
26
 
23
27
  Returns statistics regarding the book you are working on:
package/hdoc-build.js CHANGED
@@ -565,94 +565,6 @@
565
565
  sorted: true
566
566
  };
567
567
 
568
- const build_breadcrumbs = function (nav_items) {
569
- console.log('Processing navigation breadcrumbs...\n');
570
- // Steve - need to rework this to use recursion, as it's hard-coded for a maximum of 4 levels deep right now
571
- for (let a = 0; a < nav_items.length; a++) {
572
- const nav_a = nav_items[a];
573
- const parent_a = nav_a.text;
574
- if (nav_a.link) {
575
- bc[nav_a.link] = [{
576
- text: nav_a.text,
577
- link: nav_a.link
578
- }];
579
- }
580
- if (nav_a.items) {
581
- for (let b = 0; b < nav_a.items.length; b++) {
582
- const nav_b = nav_a.items[b];
583
- const parent_b = nav_b.text;
584
- if (nav_b.link) {
585
- if (bc[nav_a.link]) {
586
- bc[nav_b.link] = bc[nav_a.link];
587
- } else {
588
- bc[nav_b.link] = [{
589
- text: parent_a,
590
- link: nav_a.items[0].link
591
- }];
592
- }
593
- bc[nav_b.link].push({
594
- text: nav_b.text,
595
- link: nav_b.link
596
- });
597
- }
598
-
599
- if (nav_b.items) {
600
- for (let c = 0; c < nav_b.items.length; c++) {
601
- const nav_c = nav_b.items[c];
602
- const parent_c = nav_c.text;
603
- if (nav_c.link) {
604
- if (bc[nav_b.link]) {
605
- bc[nav_c.link] = bc[nav_b.link];
606
- } else {
607
- bc[nav_c.link] = [{
608
- text: parent_a,
609
- link: nav_a.items[0].link
610
- }];
611
- bc[nav_c.link].push({
612
- text: parent_b,
613
- link: nav_b.items[0].link
614
- });
615
- }
616
- bc[nav_c.link].push({
617
- text: nav_c.text,
618
- link: nav_c.link
619
- });
620
- }
621
-
622
- if (nav_c.items) {
623
- for (let d = 0; d < nav_c.items.length; d++) {
624
- const nav_d = nav_c.items[d];
625
- if (nav_d.link) {
626
- if (bc[nav_c.link]) {
627
- bc[nav_d.link] = bc[nav_c.link];
628
- } else {
629
- bc[nav_d.link] = [{
630
- text: parent_a,
631
- link: nav_a.items[0].link
632
- }];
633
- bc[nav_d.link].push({
634
- text: parent_b,
635
- link: nav_b.items[0].link
636
- });
637
- bc[nav_d.link].push({
638
- text: parent_c,
639
- link: nav_c.items[0].link
640
- });
641
- }
642
- bc[nav_d.link].push({
643
- text: nav_d.text,
644
- link: nav_d.link
645
- });
646
- }
647
- }
648
- }
649
- }
650
- }
651
- }
652
- }
653
- }
654
- };
655
-
656
568
  exports.run = async function (source_path, verbose_output, github_api_token, validate) {
657
569
  if (github_api_token !== '') {
658
570
  git_token = github_api_token;
@@ -759,8 +671,8 @@
759
671
  process.exit(1);
760
672
  }
761
673
  }
762
-
763
- build_breadcrumbs(hdocbook_config.navigation.items);
674
+ console.log('Processing navigation breadcrumbs...\n');
675
+ bc = hdoc.build_breadcrumbs(hdocbook_config.navigation.items);
764
676
 
765
677
  console.log('Processing content...');
766
678
  // Get a list of MD files in work_path
package/hdoc-create.js ADDED
@@ -0,0 +1,91 @@
1
+ (function () {
2
+ 'use strict';
3
+
4
+ const fs = require('fs-extra'),
5
+ path = require('path'),
6
+ hdoc = require(path.join(__dirname, 'hdoc-module.js'));
7
+
8
+ let doc_id,
9
+ processed_links = {},
10
+ file_count = 0,
11
+ folder_count = 0;
12
+
13
+ exports.run = async function (source_path) {
14
+
15
+ console.log('Hornbill HDocBook Create', '\n');
16
+ console.log('Path:', source_path, '\n');
17
+
18
+ // Load the hdocbook-project.json file to get the docId
19
+ // use the docId to get the book config
20
+ const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
21
+ let hdocbook_project = {};
22
+ try {
23
+ hdocbook_project = require(hdocbook_project_config_path);
24
+ } catch (e) {
25
+ console.log(`File not found: ${hdocbook_project_config_path}\n`);
26
+ console.log('hdoc create needs to be run in the root of a HDoc Book.\n');
27
+ process.exit(1);
28
+ }
29
+ doc_id = hdocbook_project.docId;
30
+
31
+ const book_path = path.join(source_path, doc_id),
32
+ hdocbook_path = path.join(book_path, 'hdocbook.json');
33
+
34
+ let hdocbook = {};
35
+ try {
36
+ hdocbook = require(hdocbook_path);
37
+ } catch (e) {
38
+ console.log(`File not found: ${hdocbook_path}\n`);
39
+ console.log('hdoc create needs to be run in the root of a HDoc Book.\n');
40
+ process.exit(1);
41
+ }
42
+
43
+ // Get paths from breadcrumb builder
44
+ let nav_paths = hdoc.build_breadcrumbs(hdocbook.navigation.items);
45
+ for (const key in nav_paths) {
46
+ if (nav_paths.hasOwnProperty(key)) {
47
+ for (let i = 0; i < nav_paths[key].length; i++) {
48
+ if (!processed_links[nav_paths[key][i].link]) {
49
+ nav_paths[key][i].path = path.join(source_path, nav_paths[key][i].link);
50
+ await add_doc(nav_paths[key][i]);
51
+ }
52
+ }
53
+ }
54
+ }
55
+ console.log('\n-----------------------');
56
+ console.log(' Docs Creation Summary');
57
+ console.log('-----------------------\n');
58
+ console.log(` Files Created: ${file_count}`);
59
+ console.log(`Folders Created: ${folder_count}\n`);
60
+ };
61
+
62
+ const add_doc = async function(doc_info) {
63
+
64
+ // Does folder exist? Create if not
65
+ const folder = path.dirname(doc_info.path);
66
+ if (!fs.existsSync(folder)) {
67
+ try {
68
+ fs.mkdirSync(folder, true);
69
+ console.log('Folder created:', folder);
70
+ folder_count++;
71
+ } catch {
72
+ console.log('\nError creating folder', folder, ':', e);
73
+ return;
74
+ }
75
+ }
76
+
77
+ // Does file exist? Create if not
78
+ if (!fs.existsSync(doc_info.path + '.md') && !fs.existsSync(doc_info.path + '.htm') && !fs.existsSync(doc_info.path + '.html')) {
79
+ try {
80
+ const file_path = doc_info.path + '.md';
81
+ fs.writeFileSync(file_path, `# ${doc_info.text}\n`);
82
+ console.log(' File created:', file_path);
83
+ processed_links[doc_info.link] = true;
84
+ file_count++;
85
+ } catch (e) {
86
+ console.log('\nError creating file', doc_info.path, ':', e);
87
+ }
88
+ }
89
+ }
90
+
91
+ })();
package/hdoc-help.js CHANGED
@@ -14,6 +14,9 @@ Commands
14
14
  - build
15
15
  Performs a local build of the book, and outputs as a ZIP file
16
16
 
17
+ - createDocs
18
+ Creates folder structure and markdown documents as defined in the HDocBook navigation item links
19
+
17
20
  - help
18
21
  Outputs available arguments and switches
19
22
 
package/hdoc-module.js CHANGED
@@ -290,4 +290,94 @@
290
290
  return response;
291
291
  };
292
292
 
293
+
294
+ exports.build_breadcrumbs = function (nav_items) {
295
+ let bc = {};
296
+ // Steve - need to rework this to use recursion, as it's hard-coded for a maximum of 4 levels deep right now
297
+ for (let a = 0; a < nav_items.length; a++) {
298
+ const nav_a = nav_items[a];
299
+ const parent_a = nav_a.text;
300
+ if (nav_a.link) {
301
+ bc[nav_a.link] = [{
302
+ text: nav_a.text,
303
+ link: nav_a.link
304
+ }];
305
+ }
306
+ if (nav_a.items) {
307
+ for (let b = 0; b < nav_a.items.length; b++) {
308
+ const nav_b = nav_a.items[b];
309
+ const parent_b = nav_b.text;
310
+ if (nav_b.link) {
311
+ if (bc[nav_a.link]) {
312
+ bc[nav_b.link] = bc[nav_a.link];
313
+ } else {
314
+ bc[nav_b.link] = [{
315
+ text: parent_a,
316
+ link: nav_a.items[0].link
317
+ }];
318
+ }
319
+ bc[nav_b.link].push({
320
+ text: nav_b.text,
321
+ link: nav_b.link
322
+ });
323
+ }
324
+
325
+ if (nav_b.items) {
326
+ for (let c = 0; c < nav_b.items.length; c++) {
327
+ const nav_c = nav_b.items[c];
328
+ const parent_c = nav_c.text;
329
+ if (nav_c.link) {
330
+ if (bc[nav_b.link]) {
331
+ bc[nav_c.link] = bc[nav_b.link];
332
+ } else {
333
+ bc[nav_c.link] = [{
334
+ text: parent_a,
335
+ link: nav_a.items[0].link
336
+ }];
337
+ bc[nav_c.link].push({
338
+ text: parent_b,
339
+ link: nav_b.items[0].link
340
+ });
341
+ }
342
+ bc[nav_c.link].push({
343
+ text: nav_c.text,
344
+ link: nav_c.link
345
+ });
346
+ }
347
+
348
+ if (nav_c.items) {
349
+ for (let d = 0; d < nav_c.items.length; d++) {
350
+ const nav_d = nav_c.items[d];
351
+ if (nav_d.link) {
352
+ if (bc[nav_c.link]) {
353
+ bc[nav_d.link] = bc[nav_c.link];
354
+ } else {
355
+ bc[nav_d.link] = [{
356
+ text: parent_a,
357
+ link: nav_a.items[0].link
358
+ }];
359
+ bc[nav_d.link].push({
360
+ text: parent_b,
361
+ link: nav_b.items[0].link
362
+ });
363
+ bc[nav_d.link].push({
364
+ text: parent_c,
365
+ link: nav_c.items[0].link
366
+ });
367
+ }
368
+ bc[nav_d.link].push({
369
+ text: nav_d.text,
370
+ link: nav_d.link
371
+ });
372
+ }
373
+ }
374
+ }
375
+ }
376
+ }
377
+ }
378
+ }
379
+ }
380
+ return bc;
381
+ };
382
+
293
383
  })();
package/hdoc-validate.js CHANGED
@@ -190,6 +190,23 @@
190
190
  }
191
191
  };
192
192
 
193
+ const checkTags = async function (htmlFile) {
194
+ const htmlBody = fs.readFileSync(htmlFile.path, 'utf8');
195
+ const $ = cheerio.load(htmlBody);
196
+
197
+ const h1_tags = $('h1').map(function () {
198
+ return $(this);
199
+ }).get();
200
+ if (h1_tags.length && h1_tags.length > 1) {
201
+ let error_msg = `${h1_tags.length} <h1> tags found in content: `;
202
+ for (let i = 0; i < h1_tags.length; i++) {
203
+ error_msg += h1_tags[i].text();
204
+ if (i < h1_tags.length - 1) error_msg += '; ';
205
+ }
206
+ errors[htmlFile.relativePath].push(error_msg);
207
+ }
208
+ };
209
+
193
210
  const dreeOptions = {
194
211
  descendants: true,
195
212
  depth: 10,
@@ -376,6 +393,9 @@
376
393
  await checkImages(source_path, html_to_validate[i], links.img);
377
394
  }
378
395
 
396
+ // Check for multiple H1 tags
397
+ await checkTags(html_to_validate[i]);
398
+
379
399
  // Build list content for Google
380
400
  listContent += `/${html_to_validate[i].relativePath.replace(path.extname(html_to_validate[i].relativePath), '')}`;
381
401
  if (i < html_to_validate.length - 1) {
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
 
@@ -69,6 +69,9 @@
69
69
  } else if (command == 'build') {
70
70
  const builder = require(path.join(__dirname, 'hdoc-build.js'));
71
71
  await builder.run(source_path, verbose, git_token, false);
72
+ } else if (command == 'createDocs') {
73
+ const creator = require(path.join(__dirname, 'hdoc-create.js'));
74
+ await creator.run(source_path);
72
75
  } else if (command == 'validate') {
73
76
  const builder = require(path.join(__dirname, 'hdoc-build.js'));
74
77
  await builder.run(source_path, verbose, git_token, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.9.11",
3
+ "version": "0.9.13",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -12,6 +12,7 @@
12
12
  "hdoc-build.js",
13
13
  "hdoc-build-db.js",
14
14
  "hdoc-build-pdf.js",
15
+ "hdoc-create.js",
15
16
  "hdoc-help.js",
16
17
  "hdoc-init.js",
17
18
  "hdoc-module.js",
@@ -110,9 +110,9 @@ function listenForHrefClicks()
110
110
  ev.preventDefault();
111
111
 
112
112
  //-- do we need to scroll into view element on this page
113
- if(checkUrl.hash && $(checkUrl.hash +".faq-toc-item")[0])
113
+ if(checkUrl.hash && getAnchorFromHash(checkUrl.hash,"faq-toc-item"))
114
114
  {
115
- $(checkUrl.hash +".faq-toc-item")[0].scrollIntoView();
115
+ getAnchorFromHash(checkUrl.hash,"faq-toc-item").scrollIntoView();
116
116
  if(ele.href!==document.location.href) window.history.pushState(null, null, ele.href); //-- user has clicked a link so we want to add state to history so we can click back
117
117
  }
118
118
  else
@@ -166,6 +166,31 @@ function highlightNavigationLinkFromUrl(matchLinkHref)
166
166
  });
167
167
  }
168
168
 
169
+ function getAnchorFromHash(strHash,strHasClass)
170
+ {
171
+ try{
172
+ let strSelector = toSeoUrl(strHash.replace("#",""));
173
+ if(strHasClass)strSelector += "." + strHasClass;
174
+
175
+ let jqEle = $("#"+strSelector);
176
+ if(jqEle[0])
177
+ {
178
+ return jqEle;
179
+ }
180
+ else
181
+ {
182
+ return null;
183
+ }
184
+ }
185
+ catch(e)
186
+ {
187
+ console.log("Get document anchor element by hash failed ["+strHash+"]",e);
188
+ return null;
189
+ }
190
+
191
+ }
192
+
193
+
169
194
  //-- create items to stick in toc from current loaded content
170
195
  //-- searches for H2,H3
171
196
  function generateTableOfContentsFromDoc()
@@ -361,7 +386,8 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
361
386
  //-- scroll to element that match hash (if have one)
362
387
  if(document.location.hash)
363
388
  {
364
- $(document.location.hash)[0].scrollIntoView();
389
+ let gotoEle = getAnchorFromHash(document.location.hash) ;
390
+ if(gotoEle)gotoEle[0].scrollIntoView();
365
391
  }
366
392
  });
367
393
  view.$forceUpdate();
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Hornbill Docs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.