hdoc-tools 0.7.20 → 0.7.22
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 +5 -0
- package/hdoc-db.js +158 -0
- package/hdoc-serve.js +1 -1
- package/hdoc.js +9 -4
- package/package.json +3 -1
- package/ui/js/doc.hornbill.js +3 -2
- package/LICENSE +0 -21
package/hdoc-build.js
CHANGED
|
@@ -37,8 +37,13 @@
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Render markdown into HTML
|
|
40
|
+
frontmatter_content = "";
|
|
40
41
|
var html_txt = md.render(md_txt.toString());
|
|
41
42
|
|
|
43
|
+
if (frontmatter_content.length) {
|
|
44
|
+
html_txt = "<!--[[FRONTMATTER\r\n" + frontmatter_content + "]]-->\r\n" + html_txt;
|
|
45
|
+
}
|
|
46
|
+
|
|
42
47
|
// Save HTML into HTML file
|
|
43
48
|
const target_file = file_path.replace(path.extname(file_path), '.html');
|
|
44
49
|
fs.writeFile(target_file, html_txt, function writeJSON(err) {
|
package/hdoc-db.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
const { nextTick } = require('process');
|
|
2
|
+
|
|
3
|
+
(function() {
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const dree = require('dree'),
|
|
7
|
+
fs = require('fs-extra'),
|
|
8
|
+
html2text = require('html-to-text'),
|
|
9
|
+
sqlite3 = require('sqlite3'),
|
|
10
|
+
path = require('path');
|
|
11
|
+
|
|
12
|
+
const table_name = 'hbdocs';
|
|
13
|
+
|
|
14
|
+
let db_name = 'hbdocs.db',
|
|
15
|
+
hdocbook_meta = null,
|
|
16
|
+
md_files = [];
|
|
17
|
+
|
|
18
|
+
// File callbacks for scan
|
|
19
|
+
const file_callback = function (element) {
|
|
20
|
+
if (path.extname(element.path) === '.md' && !element.path.includes('_work')) {
|
|
21
|
+
md_files.push(element);
|
|
22
|
+
} else if (element.name === 'hdocbook.json') {
|
|
23
|
+
// hdocbook meta data, read and store
|
|
24
|
+
hdocbook_meta = require(element.path);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const create_table = function(db) {
|
|
29
|
+
db.exec(`
|
|
30
|
+
create table ${table_name} (
|
|
31
|
+
relative_url text primary key not null,
|
|
32
|
+
book_id text not null,
|
|
33
|
+
title text not null,
|
|
34
|
+
content text not null,
|
|
35
|
+
tags text null,
|
|
36
|
+
audience text not null
|
|
37
|
+
);
|
|
38
|
+
`, (err) => {
|
|
39
|
+
if (err !== null) {
|
|
40
|
+
console.error(`Error creating table [${table_name}]: ${err}`);
|
|
41
|
+
return false;
|
|
42
|
+
} else {
|
|
43
|
+
console.log(` Table created successfully: ${table_name}`);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const build_db = function(db, md, book_def, md_files) {
|
|
51
|
+
for (let i = 0; i < md_files.length; i++) {
|
|
52
|
+
db.exec(`
|
|
53
|
+
insert into ${table_name}
|
|
54
|
+
(book_id, title, relative_url, content, tags, audience)
|
|
55
|
+
values
|
|
56
|
+
(
|
|
57
|
+
'${book_def.docId}',
|
|
58
|
+
'${book_def.title}',
|
|
59
|
+
'${md_files[i].relativePath}',
|
|
60
|
+
'Some file content',
|
|
61
|
+
'${book_def.tags.join(';')}',
|
|
62
|
+
'${book_def.audience.join(';')}'
|
|
63
|
+
);
|
|
64
|
+
`, (err) => {
|
|
65
|
+
if (err !== null) {
|
|
66
|
+
console.error(`Error inserting record [${md_files[i].relativePath}]: ${err}`);
|
|
67
|
+
return false;
|
|
68
|
+
} else {
|
|
69
|
+
console.log(` Record inserted successfully: ${md_files[i].relativePath}`);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const transform_markdown = function (file_path, md) {
|
|
77
|
+
if (fs.existsSync(file_path)) {
|
|
78
|
+
// Load markdown file
|
|
79
|
+
let md_txt = hdoc.expand_variables(fs.readFileSync(file_path, 'utf8'));
|
|
80
|
+
|
|
81
|
+
// Pull in external includes
|
|
82
|
+
const includes_processed = hdoc.process_includes(file_path, md_txt);
|
|
83
|
+
md_txt = includes_processed.body;
|
|
84
|
+
includes_found += includes_processed.found;
|
|
85
|
+
includes_success += includes_processed.success;
|
|
86
|
+
includes_failed += includes_processed.failed;
|
|
87
|
+
if (includes_processed.errors.length > 0) {
|
|
88
|
+
for (let i = 0; i < includes_processed.errors.length; i++) {
|
|
89
|
+
console.error(includes_processed.errors[i]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Render markdown into HTML
|
|
94
|
+
var html_txt = md.render(md_txt.toString());
|
|
95
|
+
|
|
96
|
+
// Save HTML into HTML file
|
|
97
|
+
const target_file = file_path.replace(path.extname(file_path), '.html');
|
|
98
|
+
fs.writeFile(target_file, html_txt, function writeJSON(err) {
|
|
99
|
+
if (err) return console.log('Error writing:', target_file, '\r\n', err);
|
|
100
|
+
});
|
|
101
|
+
conversion_success++;
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
conversion_failed++;
|
|
105
|
+
console.error('MD file does not exist:', file_path);
|
|
106
|
+
return false;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const dree_options = {
|
|
110
|
+
descendants: true,
|
|
111
|
+
depth: 10,
|
|
112
|
+
extensions: ['md','json'],
|
|
113
|
+
hash: false,
|
|
114
|
+
normalize: true,
|
|
115
|
+
size: false,
|
|
116
|
+
sizeInBytes: false,
|
|
117
|
+
stat: false,
|
|
118
|
+
symbolicLinks: false
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
exports.run = function(source_path, md) {
|
|
122
|
+
/*
|
|
123
|
+
STEVE - The purpose of this command is to allow content developers to do local builds of
|
|
124
|
+
the SQlite database and index file, for validation before commit and build
|
|
125
|
+
*/
|
|
126
|
+
dree.scan(source_path, dree_options, file_callback);
|
|
127
|
+
|
|
128
|
+
if (hdocbook_meta === null) {
|
|
129
|
+
console.error('hdocbook.json was not found, or has no content');
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
if (md_files.length === 0) {
|
|
133
|
+
console.error('No markdown files detected in', source_path);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
db_name = path.join(source_path, db_name);
|
|
138
|
+
if (fs.existsSync(db_name)) {
|
|
139
|
+
try {
|
|
140
|
+
fs.removeSync(db_name);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
console.error(`Failed to delete existing db file: ${db_name}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let db = new sqlite3.Database(db_name, (err) => {
|
|
147
|
+
if (err) {
|
|
148
|
+
console.error('Error creating database:', err);
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
console.log(`DB file created successfully: ${db_name}`);
|
|
152
|
+
if (create_table(db)) {
|
|
153
|
+
if (!hdocbook_meta.tags) hdocbook_meta.tags = [];
|
|
154
|
+
build_db(db, md, hdocbook_meta, md_files );
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
})();
|
package/hdoc-serve.js
CHANGED
package/hdoc.js
CHANGED
|
@@ -54,8 +54,9 @@ const { createCipheriv } = require('crypto');
|
|
|
54
54
|
let source_path = process.cwd();
|
|
55
55
|
let ui_path = path.join(__dirname, 'ui');
|
|
56
56
|
|
|
57
|
-
let
|
|
58
|
-
|
|
57
|
+
let command = '', // Our command to run
|
|
58
|
+
verbose = false,
|
|
59
|
+
build_index = false;
|
|
59
60
|
|
|
60
61
|
// Get options from command args
|
|
61
62
|
for (let x = 0; x < process.argv.length; x++) {
|
|
@@ -83,6 +84,7 @@ const { createCipheriv } = require('crypto');
|
|
|
83
84
|
if (process.argv[x] === '-v') {
|
|
84
85
|
verbose = true;
|
|
85
86
|
}
|
|
87
|
+
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
console.log('Hornbill HDocBook Tools v' + getHdocPackageVersion(packageFile), '\r\n');
|
|
@@ -102,8 +104,11 @@ const { createCipheriv } = require('crypto');
|
|
|
102
104
|
const init = require(path.join(__dirname, 'hdoc-init.js'));
|
|
103
105
|
init.run(__dirname, source_path, md);
|
|
104
106
|
} else if (command == 'help') {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
+
const help = require(path.join(__dirname, 'hdoc-help.js'));
|
|
108
|
+
help.run();
|
|
109
|
+
} else if (command == 'buildindex') {
|
|
110
|
+
const build_db = require(path.join(__dirname, 'hdoc-db.js'));
|
|
111
|
+
build_db.run(source_path, md);
|
|
107
112
|
} else {
|
|
108
113
|
console.log('Unknown command:', command, '\r\n');
|
|
109
114
|
console.log('Run hdoc help for information regarding this tool.\r\n');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hdoc-tools",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.22",
|
|
4
4
|
"description": "Hornbill HDocBook Development Support Tool",
|
|
5
5
|
"main": "hdoc.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"hdoc.js",
|
|
11
|
+
"hdoc-db.js",
|
|
11
12
|
"hdoc-build.js",
|
|
12
13
|
"hdoc-help.js",
|
|
13
14
|
"hdoc-init.js",
|
|
@@ -41,6 +42,7 @@
|
|
|
41
42
|
"markdown-it-front-matter": "^0.2.3",
|
|
42
43
|
"multer": "^1.4.5-lts.1",
|
|
43
44
|
"prompt": "^1.3.0",
|
|
45
|
+
"sqlite3": "^5.1.4",
|
|
44
46
|
"stream": "0.0.2",
|
|
45
47
|
"sync-request": "^6.1.0",
|
|
46
48
|
"words-count": "^2.0.2",
|
package/ui/js/doc.hornbill.js
CHANGED
|
@@ -94,7 +94,6 @@ function listenForHrefClicks()
|
|
|
94
94
|
//-- trap all link click events - we want to handle links so can cancel and load content ourselves
|
|
95
95
|
$("A").off("click").on("click", function(ev)
|
|
96
96
|
{
|
|
97
|
-
|
|
98
97
|
let ele = this;
|
|
99
98
|
if(ele.href)
|
|
100
99
|
{
|
|
@@ -304,7 +303,7 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
|
|
|
304
303
|
view.$nextTick(function()
|
|
305
304
|
{
|
|
306
305
|
//-- find any navigation links that match url and highlight
|
|
307
|
-
listenForHrefClicks();
|
|
306
|
+
// listenForHrefClicks();
|
|
308
307
|
highlightNavigationLinkFromUrl(linkRef);
|
|
309
308
|
|
|
310
309
|
//-- scroll to element that match hash (if have one)
|
|
@@ -315,6 +314,8 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
|
|
|
315
314
|
});
|
|
316
315
|
view.$forceUpdate();
|
|
317
316
|
}
|
|
317
|
+
|
|
318
|
+
listenForHrefClicks();
|
|
318
319
|
});
|
|
319
320
|
}
|
|
320
321
|
|
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.
|