hdoc-tools 0.19.8 → 0.21.0
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/custom_modules/tips.js +88 -86
- package/hdoc-build-db.js +260 -198
- package/hdoc-build-pdf.js +219 -173
- package/hdoc-build.js +1498 -1505
- package/hdoc-bump.js +123 -109
- package/hdoc-create.js +108 -95
- package/hdoc-db.js +97 -125
- package/hdoc-help.js +48 -51
- package/hdoc-init.js +181 -147
- package/hdoc-module.js +727 -722
- package/hdoc-serve.js +390 -361
- package/hdoc-stats.js +187 -184
- package/hdoc-validate.js +958 -717
- package/hdoc-ver.js +43 -43
- package/hdoc.js +142 -124
- package/package.json +60 -60
- package/templates/init/_hdocbook/hdocbook.json +23 -23
- package/templates/init/hdocbook-project.json +10 -10
- package/templates/init/package.json +8 -10
- package/ui/js/doc.hornbill.js +708 -659
- package/validateNodeVer.js +17 -14
package/custom_modules/tips.js
CHANGED
@@ -1,86 +1,88 @@
|
|
1
|
-
(
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
}
|
1
|
+
(() => {
|
2
|
+
// GS: based on markdown-it-tips extension but customized for our specific needs
|
3
|
+
|
4
|
+
const container = require("markdown-it-container");
|
5
|
+
|
6
|
+
module.exports = function md_tip_plugin(md, options) {
|
7
|
+
let containerOpenCount = 0;
|
8
|
+
const links = options ? options.links : true;
|
9
|
+
init();
|
10
|
+
return;
|
11
|
+
|
12
|
+
function icon_from_type(name) {
|
13
|
+
switch (name) {
|
14
|
+
case "note":
|
15
|
+
return {
|
16
|
+
class: "bi bi-exclamation-circle",
|
17
|
+
title: "Note",
|
18
|
+
};
|
19
|
+
case "tip":
|
20
|
+
return {
|
21
|
+
class: "bi bi-lightbulb",
|
22
|
+
title: "Tip",
|
23
|
+
};
|
24
|
+
case "important":
|
25
|
+
return {
|
26
|
+
class: "bi bi-megaphone",
|
27
|
+
title: "Important",
|
28
|
+
};
|
29
|
+
case "caution":
|
30
|
+
return {
|
31
|
+
class: "bi bi-x-circle",
|
32
|
+
title: "Caution",
|
33
|
+
};
|
34
|
+
case "warning":
|
35
|
+
return {
|
36
|
+
class: "bi bi-exclamation-triangle",
|
37
|
+
title: "Warning",
|
38
|
+
};
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
function setupContainer(name) {
|
43
|
+
md.use(container, name, {
|
44
|
+
render: (tokens, idx) => {
|
45
|
+
if (tokens[idx].nesting === 1) {
|
46
|
+
containerOpenCount += 1;
|
47
|
+
const inf = icon_from_type(name);
|
48
|
+
return `<div class="hdoc-alert alert-icon-${name}">\n<p class="hdoc-alert-title"><span class="${inf.class}"></span>${inf.title}</p>\n`;
|
49
|
+
}
|
50
|
+
containerOpenCount -= 1;
|
51
|
+
return "</div>\n";
|
52
|
+
},
|
53
|
+
});
|
54
|
+
}
|
55
|
+
|
56
|
+
function isContainerOpen() {
|
57
|
+
return containerOpenCount > 0;
|
58
|
+
}
|
59
|
+
|
60
|
+
function selfRender(tokens, idx, options, env, self) {
|
61
|
+
return self.renderToken(tokens, idx, options);
|
62
|
+
}
|
63
|
+
|
64
|
+
function setupLinks() {
|
65
|
+
const defaultRender = md.renderer.rules.link_open || selfRender;
|
66
|
+
|
67
|
+
md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
|
68
|
+
if (isContainerOpen()) {
|
69
|
+
tokens[idx].attrPush(["class", "md-tip-link"]);
|
70
|
+
}
|
71
|
+
|
72
|
+
return defaultRender(tokens, idx, options, env, self);
|
73
|
+
};
|
74
|
+
}
|
75
|
+
|
76
|
+
function init() {
|
77
|
+
setupContainer("note");
|
78
|
+
setupContainer("tip");
|
79
|
+
setupContainer("important");
|
80
|
+
setupContainer("caution");
|
81
|
+
setupContainer("warning");
|
82
|
+
|
83
|
+
if (links) {
|
84
|
+
setupLinks();
|
85
|
+
}
|
86
|
+
}
|
87
|
+
};
|
88
|
+
})();
|
package/hdoc-build-db.js
CHANGED
@@ -1,198 +1,260 @@
|
|
1
|
-
(
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
1
|
+
(() => {
|
2
|
+
const path = require("node:path");
|
3
|
+
const hdoc_index = require(path.join(__dirname, "hdoc-db.js"));
|
4
|
+
const database = require("better-sqlite3");
|
5
|
+
|
6
|
+
const db_schema = {
|
7
|
+
hdoc_index: [
|
8
|
+
"resource_url UNINDEXED",
|
9
|
+
"book_id",
|
10
|
+
"book_audience UNINDEXED",
|
11
|
+
"book_tags",
|
12
|
+
"doc_title",
|
13
|
+
"doc_content",
|
14
|
+
"doc_preview UNINDEXED",
|
15
|
+
"doc_family_id",
|
16
|
+
"doc_md5_hash UNINDEXED",
|
17
|
+
"doc_lastmod",
|
18
|
+
],
|
19
|
+
hdoc_meta: [
|
20
|
+
"resource_url",
|
21
|
+
"book_id",
|
22
|
+
"contributor_count INTEGER UNINDEXED",
|
23
|
+
"edit_url UNINDEXED",
|
24
|
+
"last_commit UNINDEXED",
|
25
|
+
"pdf_size INTEGER UNINDEXED",
|
26
|
+
],
|
27
|
+
hdoc_contributors: [
|
28
|
+
"resource_url",
|
29
|
+
"book_id",
|
30
|
+
"login",
|
31
|
+
"name",
|
32
|
+
"avatar UNINDEXED",
|
33
|
+
"url UNINDEXED",
|
34
|
+
],
|
35
|
+
hdoc_redirects: [
|
36
|
+
"resource_url",
|
37
|
+
"location_url",
|
38
|
+
"http_code INTEGER UNINDEXED",
|
39
|
+
],
|
40
|
+
};
|
41
|
+
|
42
|
+
exports.create_table = (db, table, cols, virtual, fts5) => {
|
43
|
+
const table_created = hdoc_index.create_table(
|
44
|
+
db,
|
45
|
+
table,
|
46
|
+
cols,
|
47
|
+
virtual,
|
48
|
+
fts5,
|
49
|
+
);
|
50
|
+
if (table_created !== null) {
|
51
|
+
return `\nError creating table: ${table_created}`;
|
52
|
+
}
|
53
|
+
console.log(`\nTable created: ${table}`);
|
54
|
+
return null;
|
55
|
+
};
|
56
|
+
|
57
|
+
exports.create_db = function (db_path, doc_id) {
|
58
|
+
const response = {
|
59
|
+
error: null,
|
60
|
+
db: null,
|
61
|
+
};
|
62
|
+
console.log("\nPerforming SQlite index creation...");
|
63
|
+
const db_name = path.join(db_path, doc_id, "index.db");
|
64
|
+
response.db = new database(db_name);
|
65
|
+
response.db.pragma('encoding="UTF-8"');
|
66
|
+
console.log(`\nDatabase created: ${db_name}`);
|
67
|
+
|
68
|
+
// Create tables
|
69
|
+
for (const key in db_schema) {
|
70
|
+
if (Object.hasOwn(db_schema, key)) {
|
71
|
+
const virtual = key === "hdoc_index";
|
72
|
+
const fts5 = key === "hdoc_index";
|
73
|
+
const table_created_error = this.create_table(
|
74
|
+
response.db,
|
75
|
+
key,
|
76
|
+
db_schema[key],
|
77
|
+
virtual,
|
78
|
+
fts5,
|
79
|
+
);
|
80
|
+
if (table_created_error !== null) {
|
81
|
+
console.error(table_created_error);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
return response;
|
86
|
+
};
|
87
|
+
|
88
|
+
exports.populate_redirects = (db, redirect_records, verbose = false) => {
|
89
|
+
const response = {
|
90
|
+
success: true,
|
91
|
+
errors: [],
|
92
|
+
index_success_count: 0,
|
93
|
+
};
|
94
|
+
|
95
|
+
for (let i = 0; i < redirect_records.length; i++) {
|
96
|
+
const index_vals = [
|
97
|
+
redirect_records[i].url,
|
98
|
+
redirect_records[i].location ? redirect_records[i].location : "",
|
99
|
+
redirect_records[i].code,
|
100
|
+
];
|
101
|
+
const index_response = hdoc_index.insert_record(
|
102
|
+
db,
|
103
|
+
"hdoc_redirects",
|
104
|
+
db_schema.hdoc_redirects,
|
105
|
+
index_vals,
|
106
|
+
);
|
107
|
+
if (!index_response.success) {
|
108
|
+
response.success = false;
|
109
|
+
response.errors.push(
|
110
|
+
`Redirect record creation failed - ${redirect_records[i].url}: ${index_response.error}`,
|
111
|
+
);
|
112
|
+
} else {
|
113
|
+
response.index_success_count++;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
console.log(
|
117
|
+
`\nRedirect Index Build Complete: ${response.index_success_count} document records created.`,
|
118
|
+
);
|
119
|
+
return response;
|
120
|
+
};
|
121
|
+
|
122
|
+
exports.populate_index = async (
|
123
|
+
db,
|
124
|
+
doc_id,
|
125
|
+
book_config,
|
126
|
+
index_records,
|
127
|
+
verbose = false,
|
128
|
+
) => {
|
129
|
+
const response = {
|
130
|
+
success: false,
|
131
|
+
index_success_count: 0,
|
132
|
+
error: "",
|
133
|
+
};
|
134
|
+
|
135
|
+
if (!book_config.tags) book_config.tags = [];
|
136
|
+
|
137
|
+
const indexPromises = [];
|
138
|
+
for (let i = 0; i < index_records.length; i++) {
|
139
|
+
indexPromises.push(index_records[i]);
|
140
|
+
}
|
141
|
+
let curr_file = "";
|
142
|
+
await Promise.all(
|
143
|
+
indexPromises.map(async (file) => {
|
144
|
+
let index_path_name = file.relative_path.replaceAll("\\", "/");
|
145
|
+
if (
|
146
|
+
index_path_name.endsWith("/index.md") ||
|
147
|
+
index_path_name.endsWith("/index.html") ||
|
148
|
+
index_path_name.endsWith("/index.htm")
|
149
|
+
) {
|
150
|
+
index_path_name = index_path_name.substring(
|
151
|
+
0,
|
152
|
+
index_path_name.lastIndexOf("/"),
|
153
|
+
);
|
154
|
+
}
|
155
|
+
index_path_name = `/${index_path_name.replace(path.extname(file.relative_path), "")}`;
|
156
|
+
|
157
|
+
let index_response = {
|
158
|
+
success: true,
|
159
|
+
row_id: 0,
|
160
|
+
};
|
161
|
+
let index_content_path = index_path_name;
|
162
|
+
if (file.index_html.id !== null)
|
163
|
+
index_content_path += `#${file.index_html.id}`;
|
164
|
+
if (!file.inline) {
|
165
|
+
const index_vals = [
|
166
|
+
index_content_path,
|
167
|
+
doc_id,
|
168
|
+
book_config.audience.join(","),
|
169
|
+
book_config.tags.join(","),
|
170
|
+
file.index_html.fm_props.title,
|
171
|
+
file.index_html.text,
|
172
|
+
file.index_html.preview,
|
173
|
+
book_config.productFamily,
|
174
|
+
file.md5,
|
175
|
+
file.lastmod,
|
176
|
+
];
|
177
|
+
index_response = hdoc_index.insert_record(
|
178
|
+
db,
|
179
|
+
"hdoc_index",
|
180
|
+
db_schema.hdoc_index,
|
181
|
+
index_vals,
|
182
|
+
);
|
183
|
+
}
|
184
|
+
if (!index_response.success) {
|
185
|
+
console.error(
|
186
|
+
`Index record creation failed - ${doc_id}/${file.index_html.fm_props.title}: ${index_response.error}`,
|
187
|
+
);
|
188
|
+
} else {
|
189
|
+
if (curr_file === index_path_name) return;
|
190
|
+
curr_file = index_path_name;
|
191
|
+
// Now add metadata
|
192
|
+
const meta_vals = [
|
193
|
+
index_path_name,
|
194
|
+
doc_id,
|
195
|
+
file.metadata.contributor_count,
|
196
|
+
file.metadata.edit_url,
|
197
|
+
file.metadata.last_commit,
|
198
|
+
file.pdf_size,
|
199
|
+
];
|
200
|
+
const meta_response = await hdoc_index.insert_record(
|
201
|
+
db,
|
202
|
+
"hdoc_meta",
|
203
|
+
db_schema.hdoc_meta,
|
204
|
+
meta_vals,
|
205
|
+
);
|
206
|
+
if (!meta_response.success) {
|
207
|
+
console.error(
|
208
|
+
`Index metadata record creation failed - ${doc_id}/${index_response.row_id}/${file.index_html.fm_props.title}: ${meta_response.error}`,
|
209
|
+
);
|
210
|
+
} else {
|
211
|
+
if (verbose) {
|
212
|
+
console.log(
|
213
|
+
`Inserted index record ${index_response.row_id}: ${doc_id} - ${file.index_html.fm_props.title}`,
|
214
|
+
);
|
215
|
+
console.log(
|
216
|
+
`Inserted index metadata record for index ID: ${meta_response.row_id}`,
|
217
|
+
);
|
218
|
+
}
|
219
|
+
|
220
|
+
// Now add contributor records
|
221
|
+
for (let j = 0; j < file.contributors.length; j++) {
|
222
|
+
const contrib_vals = [
|
223
|
+
index_path_name,
|
224
|
+
doc_id,
|
225
|
+
file.contributors[j].login,
|
226
|
+
file.contributors[j].name,
|
227
|
+
file.contributors[j].avatar_url,
|
228
|
+
file.contributors[j].html_url,
|
229
|
+
];
|
230
|
+
const cont_response = await hdoc_index.insert_record(
|
231
|
+
db,
|
232
|
+
"hdoc_contributors",
|
233
|
+
db_schema.hdoc_contributors,
|
234
|
+
contrib_vals,
|
235
|
+
);
|
236
|
+
if (!cont_response.success) {
|
237
|
+
console.error(
|
238
|
+
`Index document contributor record creation failed - ${doc_id}/${index_response.row_id}/${file.index_html.fm_props.title}: ${cont_response.error}`,
|
239
|
+
);
|
240
|
+
continue;
|
241
|
+
}
|
242
|
+
if (verbose) {
|
243
|
+
console.log(
|
244
|
+
`Inserted document contributor record ${cont_response.row_id}`,
|
245
|
+
);
|
246
|
+
}
|
247
|
+
}
|
248
|
+
response.index_success_count++;
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}),
|
252
|
+
);
|
253
|
+
|
254
|
+
response.success = true;
|
255
|
+
console.log(
|
256
|
+
`\nIndex Build Complete: ${response.index_success_count} document index records created.`,
|
257
|
+
);
|
258
|
+
return response;
|
259
|
+
};
|
260
|
+
})();
|