hdoc-tools 0.11.6 → 0.11.7

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
@@ -36,6 +36,7 @@
36
36
  css_templates = [],
37
37
  doc_header_template = '',
38
38
  doc_header_template_non_git = '',
39
+ global_source_path = '',
39
40
  pdf_created = 0,
40
41
  pdf_enable = false,
41
42
  pdf_header_template = '',
@@ -474,7 +475,7 @@
474
475
  contributors: contribs,
475
476
  pdf_size: pdf_size,
476
477
  md5: file_path.hash,
477
- lastmod: file_path.stat.mtime.toISOString()
478
+ lastmod: file_path.hb_lastmod
478
479
  });
479
480
 
480
481
  // Add MD file to delete queue
@@ -538,6 +539,9 @@
538
539
  // File callback for build scan
539
540
  const build_file_callback = function (element) {
540
541
  if (element.extension === 'md') {
542
+ element.hb_source_path = path.join(global_source_path, element.relativePath);
543
+ const fstats = fs.statSync(element.hb_source_path);
544
+ element.hb_lastmod = `${fstats.mtime.toISOString().slice(0, 19)}Z`;
541
545
  md_files.push(element);
542
546
  } else {
543
547
  // File is html, see if there's a matching md file and if there is then ignore the html
@@ -545,6 +549,9 @@
545
549
  if (fs.existsSync(md_path)) {
546
550
  return;
547
551
  }
552
+ element.hb_source_path = path.join(global_source_path, element.relativePath);
553
+ const fstats = fs.statSync(element.hb_source_path);
554
+ element.hb_lastmod = `${fstats.mtime.toISOString().slice(0, 19)}Z`;
548
555
  static_html_files.push(element);
549
556
  }
550
557
  };
@@ -576,6 +583,7 @@
576
583
  if (github_api_token !== '') {
577
584
  git_token = github_api_token;
578
585
  }
586
+ global_source_path = source_path;
579
587
  verbose = verbose_output;
580
588
 
581
589
  const start_time = Date.now();
package/hdoc-bump.js CHANGED
@@ -1,109 +1,109 @@
1
- (function () {
2
- 'use strict';
3
-
4
- const fs = require('fs'),
5
- path = require('path');
6
-
7
- exports.run = function (source_path, bump_type) {
8
- if (bump_type !== 'patch' && bump_type !== 'minor' && bump_type !== 'major') {
9
- console.log(`Unsupported bump type: ${bump_type}`);
10
- process.exit(1);
11
- }
12
- console.log(`Bumping ${bump_type} book version...\n`);
13
-
14
- // Get document ID
15
- const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
16
- let hdocbook_project;
17
- try {
18
- hdocbook_project = require(hdocbook_project_config_path);
19
- } catch (e) {
20
- console.log('File not found: hdocbook-project.json:');
21
- console.log(e, '\n');
22
- console.log('hdoc bump needs to be run in the root of a HDoc Book.\n');
23
- process.exit(1);
24
- }
25
- const doc_id = hdocbook_project.docId;
26
-
27
- const book_path = path.join(source_path, doc_id),
28
- hdocbook_path = path.join(book_path, 'hdocbook.json');
29
-
30
- let hdocbook_config;
31
- try {
32
- hdocbook_config = require(hdocbook_path);
33
- } catch (e) {
34
- console.log('File not found: hdocbook.json');
35
- console.log(e, '\n');
36
- console.log('hdoc bump needs to be run in the root of a HDoc Book.\n');
37
- process.exit(1);
38
- }
39
- const initial_version = hdocbook_config.version;
40
- let hdocbook_version = hdocbook_config.version.split('.');
41
- if (hdocbook_version.length !== 3) {
42
- console.log(`Book version does not appear to be in a semantic versioning format: ${initial_version}`);
43
- process.exit(1);
44
- }
45
-
46
- if (isNaN(hdocbook_version[0])) {
47
- console.log(`Existing major version is not a number: ${hdocbook_version[0]}`);
48
- process.exit(1);
49
- }
50
- if (isNaN(hdocbook_version[1])) {
51
- console.log(`Existing minor version is not a number: ${hdocbook_version[1]}`);
52
- process.exit(1);
53
- }
54
- if (isNaN(hdocbook_version[2])) {
55
- console.log(`Existing patch version is not a number: ${hdocbook_version[2]}`);
56
- process.exit(1);
57
- }
58
-
59
- switch (bump_type) {
60
- case 'major':
61
- try {
62
- hdocbook_version[0] = parseInt(hdocbook_version[0], 10) + 1;
63
- hdocbook_version[1] = 0;
64
- hdocbook_version[2] = 0;
65
- } catch (e) {
66
- console.log('Failed to update major version:');
67
- console.log(e);
68
- process.exit(1);
69
- }
70
- break;
71
- case 'minor':
72
- try {
73
- hdocbook_version[0] = parseInt(hdocbook_version[0], 10);
74
- hdocbook_version[1] = parseInt(hdocbook_version[1], 10) + 1;
75
- hdocbook_version[2] = 0;
76
- } catch (e) {
77
- console.log('Failed to update minor version:');
78
- console.log(e);
79
- process.exit(1);
80
- }
81
- break;
82
- case 'patch':
83
- default:
84
- try {
85
- hdocbook_version[0] = parseInt(hdocbook_version[0], 10);
86
- hdocbook_version[1] = parseInt(hdocbook_version[1], 10);
87
- hdocbook_version[2] = parseInt(hdocbook_version[2], 10) + 1;
88
- } catch (e) {
89
- console.log('Failed to update patch version:');
90
- console.log(e);
91
- process.exit(1);
92
- }
93
- break;
94
- }
95
-
96
- hdocbook_config.version = hdocbook_version.join('.');
97
-
98
- try {
99
- fs.writeFileSync(hdocbook_path, JSON.stringify(hdocbook_config, null, 2));
100
- } catch (e) {
101
- console.log('Error writing bumped version to book config:', e);
102
- process.exit(1);
103
- }
104
-
105
- console.log(`Book version updated from ${initial_version} to ${hdocbook_config.version}\n`);
106
- return true;
107
- };
108
-
1
+ (function () {
2
+ 'use strict';
3
+
4
+ const fs = require('fs'),
5
+ path = require('path');
6
+
7
+ exports.run = function (source_path, bump_type) {
8
+ if (bump_type !== 'patch' && bump_type !== 'minor' && bump_type !== 'major') {
9
+ console.log(`Unsupported bump type: ${bump_type}`);
10
+ process.exit(1);
11
+ }
12
+ console.log(`Bumping ${bump_type} book version...\n`);
13
+
14
+ // Get document ID
15
+ const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
16
+ let hdocbook_project;
17
+ try {
18
+ hdocbook_project = require(hdocbook_project_config_path);
19
+ } catch (e) {
20
+ console.log('File not found: hdocbook-project.json:');
21
+ console.log(e, '\n');
22
+ console.log('hdoc bump needs to be run in the root of a HDoc Book.\n');
23
+ process.exit(1);
24
+ }
25
+ const doc_id = hdocbook_project.docId;
26
+
27
+ const book_path = path.join(source_path, doc_id),
28
+ hdocbook_path = path.join(book_path, 'hdocbook.json');
29
+
30
+ let hdocbook_config;
31
+ try {
32
+ hdocbook_config = require(hdocbook_path);
33
+ } catch (e) {
34
+ console.log('File not found: hdocbook.json');
35
+ console.log(e, '\n');
36
+ console.log('hdoc bump needs to be run in the root of a HDoc Book.\n');
37
+ process.exit(1);
38
+ }
39
+ const initial_version = hdocbook_config.version;
40
+ let hdocbook_version = hdocbook_config.version.split('.');
41
+ if (hdocbook_version.length !== 3) {
42
+ console.log(`Book version does not appear to be in a semantic versioning format: ${initial_version}`);
43
+ process.exit(1);
44
+ }
45
+
46
+ if (isNaN(hdocbook_version[0])) {
47
+ console.log(`Existing major version is not a number: ${hdocbook_version[0]}`);
48
+ process.exit(1);
49
+ }
50
+ if (isNaN(hdocbook_version[1])) {
51
+ console.log(`Existing minor version is not a number: ${hdocbook_version[1]}`);
52
+ process.exit(1);
53
+ }
54
+ if (isNaN(hdocbook_version[2])) {
55
+ console.log(`Existing patch version is not a number: ${hdocbook_version[2]}`);
56
+ process.exit(1);
57
+ }
58
+
59
+ switch (bump_type) {
60
+ case 'major':
61
+ try {
62
+ hdocbook_version[0] = parseInt(hdocbook_version[0], 10) + 1;
63
+ hdocbook_version[1] = 0;
64
+ hdocbook_version[2] = 0;
65
+ } catch (e) {
66
+ console.log('Failed to update major version:');
67
+ console.log(e);
68
+ process.exit(1);
69
+ }
70
+ break;
71
+ case 'minor':
72
+ try {
73
+ hdocbook_version[0] = parseInt(hdocbook_version[0], 10);
74
+ hdocbook_version[1] = parseInt(hdocbook_version[1], 10) + 1;
75
+ hdocbook_version[2] = 0;
76
+ } catch (e) {
77
+ console.log('Failed to update minor version:');
78
+ console.log(e);
79
+ process.exit(1);
80
+ }
81
+ break;
82
+ case 'patch':
83
+ default:
84
+ try {
85
+ hdocbook_version[0] = parseInt(hdocbook_version[0], 10);
86
+ hdocbook_version[1] = parseInt(hdocbook_version[1], 10);
87
+ hdocbook_version[2] = parseInt(hdocbook_version[2], 10) + 1;
88
+ } catch (e) {
89
+ console.log('Failed to update patch version:');
90
+ console.log(e);
91
+ process.exit(1);
92
+ }
93
+ break;
94
+ }
95
+
96
+ hdocbook_config.version = hdocbook_version.join('.');
97
+
98
+ try {
99
+ fs.writeFileSync(hdocbook_path, JSON.stringify(hdocbook_config, null, 2));
100
+ } catch (e) {
101
+ console.log('Error writing bumped version to book config:', e);
102
+ process.exit(1);
103
+ }
104
+
105
+ console.log(`Book version updated from ${initial_version} to ${hdocbook_config.version}\n`);
106
+ return true;
107
+ };
108
+
109
109
  })();
package/hdoc-create.js CHANGED
@@ -1,91 +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
-
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
91
  })();
package/hdoc-db.js CHANGED
@@ -1,95 +1,95 @@
1
- (function () {
2
- 'use strict';
3
-
4
- const html2text = require('html-to-text'),
5
- path = require('path'),
6
- hdoc = require(path.join(__dirname, 'hdoc-module.js'));
7
-
8
- exports.create_table = function (db, table_name, columns, virtual, fts5) {
9
- let create_sql = ['CREATE'];
10
- if (virtual) create_sql.push('VIRTUAL');
11
- create_sql.push('TABLE');
12
- create_sql.push(table_name);
13
- if (fts5) create_sql.push('USING fts5(');
14
- else create_sql.push('(');
15
- for (let i = 0; i < columns.length; i++) {
16
- if (i !== 0) create_sql.push(`,${columns[i]}`);
17
- else create_sql.push(columns[i]);
18
- }
19
- create_sql.push(');');
20
- try {
21
- db.exec(create_sql.join('\n'));
22
- return null;
23
- } catch (e) {
24
- return e;
25
- }
26
- };
27
-
28
- exports.insert_record = function (db, table, columns, values) {
29
- let response = {
30
- success: false,
31
- row_id: 0,
32
- error: null
33
- };
34
- let queryProps = [];
35
- queryProps.push(`INSERT INTO ${table}`);
36
- let cols = '(';
37
- let vals = 'VALUES (';
38
- for (let i = 0; i < columns.length; i++) {
39
- if (i === 0) {
40
- cols += `${columns[i].replace('UNINDEXED', '').replace('INTEGER', '').trim()}`;
41
- vals += '?';
42
- } else {
43
- cols += `, ${columns[i].replace('UNINDEXED', '').replace('INTEGER', '').trim()}`;
44
- vals += ', ?';
45
- }
46
- }
47
- cols += ')';
48
- vals += ')';
49
- queryProps.push(cols);
50
- queryProps.push(vals);
51
-
52
- try {
53
- const stmt = db.prepare(queryProps.join(' '));
54
- const info = stmt.run(values);
55
- response.row_id = info.lastInsertRowid;
56
- response.success = true;
57
- } catch (e) {
58
- response.error = e;
59
- }
60
- return response;
61
- };
62
-
63
- exports.transform_html_for_index = function (html_txt) {
64
- let response = {
65
- text: '',
66
- preview: '',
67
- fm_props: {}
68
- };
69
-
70
- // Get frontmatter properties
71
- const fm_headers = hdoc.getHTMLFrontmatterHeader(html_txt);
72
- response.fm_props = fm_headers.fm_properties;
73
-
74
- // Convert HTML into plain text
75
- response.text = html2text.convert(html_txt, {
76
- ignoreHref: true,
77
- ignoreImage: true,
78
- uppercaseHeadings: false,
79
- wordwrap: null
80
- });
81
-
82
- // Convert HTML into preview text
83
- response.preview = html2text.convert(html_txt, {
84
- baseElement: 'p',
85
- ignoreHref: true,
86
- ignoreImage: true,
87
- uppercaseHeadings: false,
88
- wordwrap: null
89
- });
90
- response.preview = hdoc.truncate_string(response.preview, 200, true).replace(/(?:\r\n|\r|\n)/g, ' ');
91
- return response;
92
- };
93
-
94
-
1
+ (function () {
2
+ 'use strict';
3
+
4
+ const html2text = require('html-to-text'),
5
+ path = require('path'),
6
+ hdoc = require(path.join(__dirname, 'hdoc-module.js'));
7
+
8
+ exports.create_table = function (db, table_name, columns, virtual, fts5) {
9
+ let create_sql = ['CREATE'];
10
+ if (virtual) create_sql.push('VIRTUAL');
11
+ create_sql.push('TABLE');
12
+ create_sql.push(table_name);
13
+ if (fts5) create_sql.push('USING fts5(');
14
+ else create_sql.push('(');
15
+ for (let i = 0; i < columns.length; i++) {
16
+ if (i !== 0) create_sql.push(`,${columns[i]}`);
17
+ else create_sql.push(columns[i]);
18
+ }
19
+ create_sql.push(');');
20
+ try {
21
+ db.exec(create_sql.join('\n'));
22
+ return null;
23
+ } catch (e) {
24
+ return e;
25
+ }
26
+ };
27
+
28
+ exports.insert_record = function (db, table, columns, values) {
29
+ let response = {
30
+ success: false,
31
+ row_id: 0,
32
+ error: null
33
+ };
34
+ let queryProps = [];
35
+ queryProps.push(`INSERT INTO ${table}`);
36
+ let cols = '(';
37
+ let vals = 'VALUES (';
38
+ for (let i = 0; i < columns.length; i++) {
39
+ if (i === 0) {
40
+ cols += `${columns[i].replace('UNINDEXED', '').replace('INTEGER', '').trim()}`;
41
+ vals += '?';
42
+ } else {
43
+ cols += `, ${columns[i].replace('UNINDEXED', '').replace('INTEGER', '').trim()}`;
44
+ vals += ', ?';
45
+ }
46
+ }
47
+ cols += ')';
48
+ vals += ')';
49
+ queryProps.push(cols);
50
+ queryProps.push(vals);
51
+
52
+ try {
53
+ const stmt = db.prepare(queryProps.join(' '));
54
+ const info = stmt.run(values);
55
+ response.row_id = info.lastInsertRowid;
56
+ response.success = true;
57
+ } catch (e) {
58
+ response.error = e;
59
+ }
60
+ return response;
61
+ };
62
+
63
+ exports.transform_html_for_index = function (html_txt) {
64
+ let response = {
65
+ text: '',
66
+ preview: '',
67
+ fm_props: {}
68
+ };
69
+
70
+ // Get frontmatter properties
71
+ const fm_headers = hdoc.getHTMLFrontmatterHeader(html_txt);
72
+ response.fm_props = fm_headers.fm_properties;
73
+
74
+ // Convert HTML into plain text
75
+ response.text = html2text.convert(html_txt, {
76
+ ignoreHref: true,
77
+ ignoreImage: true,
78
+ uppercaseHeadings: false,
79
+ wordwrap: null
80
+ });
81
+
82
+ // Convert HTML into preview text
83
+ response.preview = html2text.convert(html_txt, {
84
+ baseElement: 'p',
85
+ ignoreHref: true,
86
+ ignoreImage: true,
87
+ uppercaseHeadings: false,
88
+ wordwrap: null
89
+ });
90
+ response.preview = hdoc.truncate_string(response.preview, 200, true).replace(/(?:\r\n|\r|\n)/g, ' ');
91
+ return response;
92
+ };
93
+
94
+
95
95
  })();