hdoc-tools 0.11.8 → 0.12.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/hdoc-build-db.js +31 -1
- package/hdoc-build.js +27 -6
- package/hdoc-serve.js +15 -18
- package/hdoc-validate.js +48 -2
- package/package.json +1 -1
package/hdoc-build-db.js
CHANGED
@@ -33,6 +33,11 @@
|
|
33
33
|
'name',
|
34
34
|
'avatar UNINDEXED',
|
35
35
|
'url UNINDEXED'
|
36
|
+
],
|
37
|
+
hdoc_redirects: [
|
38
|
+
'resource_url',
|
39
|
+
'location_url',
|
40
|
+
'http_code INTEGER UNINDEXED'
|
36
41
|
]
|
37
42
|
};
|
38
43
|
|
@@ -71,6 +76,31 @@
|
|
71
76
|
return response;
|
72
77
|
};
|
73
78
|
|
79
|
+
exports.populate_redirects = function (db, redirect_records, verbose = false) {
|
80
|
+
let response = {
|
81
|
+
success: true,
|
82
|
+
errors: [],
|
83
|
+
index_success_count: 0
|
84
|
+
};
|
85
|
+
|
86
|
+
for (let i = 0; i < redirect_records.length; i++) {
|
87
|
+
const index_vals = [
|
88
|
+
redirect_records[i].url,
|
89
|
+
redirect_records[i].location ? redirect_records[i].location : '',
|
90
|
+
redirect_records[i].code
|
91
|
+
];
|
92
|
+
const index_response = hdoc_index.insert_record(db, 'hdoc_redirects', db_schema.hdoc_redirects, index_vals);
|
93
|
+
if (!index_response.success) {
|
94
|
+
response.success = false;
|
95
|
+
response.errors.push(`Redirect record creation failed - ${redirect_records[i].url}: ${index_response.error}`);
|
96
|
+
} else {
|
97
|
+
response.index_success_count++
|
98
|
+
}
|
99
|
+
}
|
100
|
+
console.log(`\nRedirect Index Build Complete: ${response.index_success_count} document records created.`);
|
101
|
+
return response;
|
102
|
+
};
|
103
|
+
|
74
104
|
exports.populate_index = async function (db, doc_id, book_config, index_records, verbose = false) {
|
75
105
|
let response = {
|
76
106
|
success: false,
|
@@ -137,7 +167,7 @@
|
|
137
167
|
continue;
|
138
168
|
}
|
139
169
|
if (verbose) {
|
140
|
-
console.log(`Inserted document contributor
|
170
|
+
console.log(`Inserted document contributor record ${cont_response.row_id}`);
|
141
171
|
}
|
142
172
|
}
|
143
173
|
response.index_success_count++;
|
package/hdoc-build.js
CHANGED
@@ -54,6 +54,7 @@
|
|
54
54
|
index_records = [],
|
55
55
|
md_files = [],
|
56
56
|
md_files_delete = [],
|
57
|
+
redirects = {},
|
57
58
|
static_html_files = [],
|
58
59
|
work_path_content = '',
|
59
60
|
verbose = false;
|
@@ -528,7 +529,14 @@
|
|
528
529
|
let bc_tags = '\n';
|
529
530
|
if (bc_for_path) {
|
530
531
|
for (let i = 0; i < bc_for_path.length - 1; i++) {
|
531
|
-
|
532
|
+
let bc_link = '/';
|
533
|
+
if (redirects[bc_for_path[i].link]) {
|
534
|
+
if (redirects[bc_for_path[i].link].location) {
|
535
|
+
bc_link += redirects[bc_for_path[i].link].location;
|
536
|
+
}
|
537
|
+
} else {
|
538
|
+
bc_link = bc_for_path[i].link.startsWith('/') ? bc_for_path[i].link : `/${bc_for_path[i].link}`;
|
539
|
+
}
|
532
540
|
bc_tags += `\t\t\t\t<li class="mt-0 nav-bar-item"><a href="${bc_link}" class="ps-0 pe-0 text-decoration-none">${bc_for_path[i].text}</a></li>\n`;
|
533
541
|
}
|
534
542
|
} else {
|
@@ -622,6 +630,12 @@
|
|
622
630
|
pdf_enable = hdocbook_project.pdfGeneration.enable;
|
623
631
|
}
|
624
632
|
|
633
|
+
if (hdocbook_project.redirects && hdocbook_project.redirects instanceof Array) {
|
634
|
+
for (let i = 0; i < hdocbook_project.redirects.length; i++) {
|
635
|
+
redirects[hdocbook_project.redirects[i].url] = hdocbook_project.redirects[i];
|
636
|
+
}
|
637
|
+
}
|
638
|
+
|
625
639
|
console.log(`Loading hdocbook config...`);
|
626
640
|
|
627
641
|
const book_path = path.join(source_path, doc_id),
|
@@ -777,7 +791,6 @@
|
|
777
791
|
}));
|
778
792
|
}
|
779
793
|
|
780
|
-
|
781
794
|
if (pdf_enable) {
|
782
795
|
// Close the Chromium browser instance
|
783
796
|
await browser.close();
|
@@ -796,7 +809,7 @@
|
|
796
809
|
}
|
797
810
|
|
798
811
|
// Validate content
|
799
|
-
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc, prod_families, prods_supported, gen_exclude);
|
812
|
+
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc, prod_families, prods_supported, gen_exclude, redirects);
|
800
813
|
if (!validation_success) {
|
801
814
|
const end_time = Date.now();
|
802
815
|
console.log(`\nTime Taken: ${get_duration(start_time, end_time)}\n`);
|
@@ -835,14 +848,22 @@
|
|
835
848
|
console.log(db.error);
|
836
849
|
process.exit(1);
|
837
850
|
}
|
838
|
-
|
851
|
+
// Populate primary index tables
|
839
852
|
const index = await hdoc_build_db.populate_index(db.db, doc_id, hdocbook_config, index_records, verbose);
|
840
853
|
if (!index.success) {
|
841
854
|
console.log(index.error);
|
842
855
|
process.exit(1);
|
843
856
|
}
|
844
|
-
|
845
|
-
|
857
|
+
|
858
|
+
// Populate redirect index table records
|
859
|
+
if (hdocbook_project.redirects && hdocbook_project.redirects instanceof Array && hdocbook_project.redirects.length > 0) {
|
860
|
+
const redirects_index = hdoc_build_db.populate_redirects(db.db, hdocbook_project.redirects, verbose);
|
861
|
+
if (!redirects_index.success) {
|
862
|
+
for (let i = 0; i < index.errors.length; i++) {
|
863
|
+
console.log(index.errors[i]);
|
864
|
+
}
|
865
|
+
process.exit(1);
|
866
|
+
}
|
846
867
|
}
|
847
868
|
|
848
869
|
if (!validate) {
|
package/hdoc-serve.js
CHANGED
@@ -35,7 +35,7 @@
|
|
35
35
|
console.log(' Server Port:', port);
|
36
36
|
|
37
37
|
if (fs.existsSync(path.join(source_path, 'hdocbook-project.json')) == false) {
|
38
|
-
console.log("No hdocbook-project.
|
38
|
+
console.log("No hdocbook-project.json file found in working folder. Unable to continue.");
|
39
39
|
return -1;
|
40
40
|
}
|
41
41
|
|
@@ -83,9 +83,9 @@
|
|
83
83
|
md_txt = includes_processed.body;
|
84
84
|
if (includes_processed.errors && includes_processed.errors.length > 0) {
|
85
85
|
console.error(`Error(s) when processing includes in ${file_path}`);
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
for (let i = 0; i < includes_processed.errors.length; i++) {
|
87
|
+
console.error(includes_processed.errors[i]);
|
88
|
+
}
|
89
89
|
} else {
|
90
90
|
if (includes_processed.found > 0) {
|
91
91
|
console.log(`Includes injected into document: ${includes_processed.success}`);
|
@@ -93,22 +93,19 @@
|
|
93
93
|
}
|
94
94
|
|
95
95
|
const md = require('markdown-it')({
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
// }
|
107
|
-
});
|
108
|
-
|
96
|
+
// enable everything
|
97
|
+
html: true,
|
98
|
+
linkify: true,
|
99
|
+
typographer: true
|
100
|
+
});
|
101
|
+
md.linkify.set({
|
102
|
+
fuzzyEmail: false,
|
103
|
+
fuzzyLink: false,
|
104
|
+
fuzzyIP: false
|
105
|
+
});
|
109
106
|
var frontmatter_content = "";
|
110
107
|
md.use(mdfm, function (fm) {
|
111
|
-
|
108
|
+
frontmatter_content = fm;
|
112
109
|
});
|
113
110
|
|
114
111
|
const tips = require(__dirname + '/custom_modules/tips.js');
|
package/hdoc-validate.js
CHANGED
@@ -27,6 +27,7 @@
|
|
27
27
|
md_to_validate = [],
|
28
28
|
exclude_links = {},
|
29
29
|
exclude_spellcheck = {},
|
30
|
+
redirects = {},
|
30
31
|
exclude_h1_count = {},
|
31
32
|
exclude_spellcheck_output = [];
|
32
33
|
|
@@ -97,6 +98,17 @@
|
|
97
98
|
const key_split = key.split('#');
|
98
99
|
const key_no_hash = key_split[0];
|
99
100
|
|
101
|
+
// See if there's a redirect in place
|
102
|
+
let redirected = false;
|
103
|
+
let redirect_errored = false;
|
104
|
+
const redir = await checkRedirect(source_path, key_no_hash);
|
105
|
+
if (redir.exists && redir.error !== null) {
|
106
|
+
nav_errors.push(redir.error);
|
107
|
+
redirect_errored = true;
|
108
|
+
} else if (redir.exists && redir.error === null) {
|
109
|
+
redirected = true;
|
110
|
+
}
|
111
|
+
|
100
112
|
// Validate path exists - key should be a html file at this point
|
101
113
|
let file_exists = true;
|
102
114
|
let file_name = path.join(source_path, key_no_hash + '.html');
|
@@ -108,13 +120,19 @@
|
|
108
120
|
file_name = path.join(source_path, key_no_hash, 'index.htm');
|
109
121
|
if (!fs.existsSync(file_name)) {
|
110
122
|
file_exists = false;
|
111
|
-
|
123
|
+
if (!redirected && !redirect_errored)
|
124
|
+
nav_errors.push(`Navigation path [${key_no_hash}] file does not exist.`);
|
112
125
|
}
|
113
126
|
}
|
114
127
|
}
|
115
128
|
}
|
116
129
|
|
117
130
|
if (file_exists) {
|
131
|
+
// File exists - but is there a redirect? If so, we want to flag this as an error
|
132
|
+
if (redirected)
|
133
|
+
nav_errors.push(`Navigation path [${key_no_hash}] is redirected, but path still exists.`);
|
134
|
+
|
135
|
+
// Check file path case match
|
118
136
|
const true_file = trueCasePathSync(file_name).replace(source_path, '').replaceAll('\\', '/');
|
119
137
|
const relative_file = file_name.replace(source_path, '').replaceAll('\\', '/');
|
120
138
|
if (true_file !== relative_file) {
|
@@ -175,6 +193,33 @@
|
|
175
193
|
return nav_errors;
|
176
194
|
};
|
177
195
|
|
196
|
+
const checkRedirect = async function (source_path, nav_path) {
|
197
|
+
let response = {
|
198
|
+
exists: false,
|
199
|
+
error: null
|
200
|
+
}
|
201
|
+
if (redirects[nav_path]) {
|
202
|
+
response.exists = true;
|
203
|
+
if (redirects[nav_path].location) {
|
204
|
+
// We have a redirect, check if it's a valid location
|
205
|
+
let file_path = path.join(source_path, redirects[nav_path].location + '.html');
|
206
|
+
if (!fs.existsSync(file_path)) {
|
207
|
+
file_path = path.join(source_path, redirects[nav_path].location + '.htm');
|
208
|
+
if (!fs.existsSync(file_path)) {
|
209
|
+
file_path = path.join(source_path, redirects[nav_path].location, 'index.html');
|
210
|
+
if (!fs.existsSync(file_path)) {
|
211
|
+
file_path = path.join(source_path, redirects[nav_path].location, 'index.htm');
|
212
|
+
if (!fs.existsSync(file_path)) {
|
213
|
+
response.error = `Redirect path for [${nav_path}] does not exist: ${redirects[nav_path].location}`;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
return response;
|
221
|
+
}
|
222
|
+
|
178
223
|
const checkLinks = async function (source_path, htmlFile, links, hdocbook_config) {
|
179
224
|
for (let i = 0; i < links.length; i++) {
|
180
225
|
|
@@ -369,8 +414,9 @@
|
|
369
414
|
return links;
|
370
415
|
};
|
371
416
|
|
372
|
-
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items, prod_families, prods_supported, gen_exclude) {
|
417
|
+
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items, prod_families, prods_supported, gen_exclude, gen_redirects) {
|
373
418
|
console.log(`Performing Validation and Building SEO Link List...`);
|
419
|
+
redirects = gen_redirects;
|
374
420
|
|
375
421
|
// Get a list of HTML files in source_path
|
376
422
|
dree.scan(source_path, dreeOptions, fileCallback);
|