hdoc-tools 0.9.2 → 0.9.3
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 +1 -1
- package/hdoc-validate.js +36 -15
- package/package.json +1 -1
package/hdoc-build.js
CHANGED
@@ -793,7 +793,7 @@
|
|
793
793
|
console.log(` Static HTML Files Found: ${static_html_files.length}\n`);
|
794
794
|
|
795
795
|
// Validate content
|
796
|
-
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project);
|
796
|
+
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc);
|
797
797
|
if (!validation_success) {
|
798
798
|
process.exit(1);
|
799
799
|
}
|
package/hdoc-validate.js
CHANGED
@@ -22,7 +22,8 @@
|
|
22
22
|
warnings = {},
|
23
23
|
errorcount = 0,
|
24
24
|
html_files = [],
|
25
|
-
exclude_links = {}
|
25
|
+
exclude_links = {},
|
26
|
+
exclude_spellcheck = {};
|
26
27
|
|
27
28
|
const load_product_families = async function() {
|
28
29
|
try {
|
@@ -40,16 +41,19 @@
|
|
40
41
|
return true;
|
41
42
|
};
|
42
43
|
|
43
|
-
const
|
44
|
-
|
45
|
-
const text = html2text.convert(htmlBody, {
|
46
|
-
wordwrap: null
|
47
|
-
});
|
48
|
-
|
44
|
+
const checkBritishSpelling = async function(source, excludes, text) {
|
45
|
+
if (!errors[source]) errors[source] = [];
|
49
46
|
var options = {
|
50
47
|
british: true,
|
51
48
|
spelling: true
|
52
49
|
};
|
50
|
+
|
51
|
+
let rel_source = source.replaceAll('\\', '/');
|
52
|
+
rel_source = rel_source.substring(0, rel_source.length - path.extname(source).length);
|
53
|
+
if (rel_source.includes('/_work/')) {
|
54
|
+
rel_source = rel_source.split('/_work/')[1];
|
55
|
+
}
|
56
|
+
|
53
57
|
const translate_output = translator.translate(text, options);
|
54
58
|
if(Object.keys(translate_output).length){
|
55
59
|
for (const key in translate_output) {
|
@@ -58,7 +62,11 @@
|
|
58
62
|
for (let i = 0; i < translate_output[key].length; i++) {
|
59
63
|
for (const spelling in translate_output[key][i]) {
|
60
64
|
if (translate_output[key][i].hasOwnProperty(spelling)) {
|
61
|
-
|
65
|
+
if (!excludes[rel_source]) {
|
66
|
+
errors[source].push(`${error_message} ${spelling} should be ${translate_output[key][i][spelling].details}`);
|
67
|
+
} else if (!excludes[rel_source].includes(spelling.toLowerCase())) {
|
68
|
+
errors[source].push(`${error_message} ${spelling} should be ${translate_output[key][i][spelling].details}`);
|
69
|
+
}
|
62
70
|
}
|
63
71
|
}
|
64
72
|
}
|
@@ -67,6 +75,14 @@
|
|
67
75
|
}
|
68
76
|
};
|
69
77
|
|
78
|
+
const checkBritishSpellings = async function (htmlFile, excludes) {
|
79
|
+
const htmlBody = fs.readFileSync(htmlFile.path, 'utf8');
|
80
|
+
const text = html2text.convert(htmlBody, {
|
81
|
+
wordwrap: null
|
82
|
+
});
|
83
|
+
checkBritishSpelling(htmlFile.path, excludes, text);
|
84
|
+
};
|
85
|
+
|
70
86
|
const checkLinks = async function (source_path, htmlFile, links, hdocbook_config) {
|
71
87
|
for (let i = 0; i < links.length; i++) {
|
72
88
|
|
@@ -226,7 +242,7 @@
|
|
226
242
|
return links;
|
227
243
|
};
|
228
244
|
|
229
|
-
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project) {
|
245
|
+
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items) {
|
230
246
|
console.log(`Performing Validation and Building SEO Link List...`);
|
231
247
|
|
232
248
|
// Load product families
|
@@ -248,16 +264,21 @@
|
|
248
264
|
console.log('-----------------------\r\n');
|
249
265
|
console.log(`- Incorrect productFamily: ${hdocbook_config.productFamily}`)
|
250
266
|
console.log(`\r\n1 Validation Errors Found\r\n`);
|
251
|
-
console.log(``)
|
252
267
|
return false;
|
253
268
|
}
|
254
269
|
|
255
|
-
if (hdocbook_project.validation
|
256
|
-
hdocbook_project.validation.exclude_links.
|
257
|
-
|
270
|
+
if (hdocbook_project.validation) {
|
271
|
+
if (hdocbook_project.validation.exclude_links && hdocbook_project.validation.exclude_links instanceof Array) {
|
272
|
+
hdocbook_project.validation.exclude_links.forEach(function(excl_link) {
|
273
|
+
exclude_links[excl_link] = true;
|
274
|
+
});
|
275
|
+
}
|
276
|
+
if (hdocbook_project.validation.exclude_spellcheck && hdocbook_project.validation.exclude_spellcheck instanceof Array) {
|
277
|
+
hdocbook_project.validation.exclude_spellcheck.forEach(function(excl_sc) {
|
278
|
+
exclude_spellcheck[excl_sc.document_path] = excl_sc.words;
|
258
279
|
});
|
259
280
|
}
|
260
|
-
|
281
|
+
}
|
261
282
|
|
262
283
|
let listContent = '';
|
263
284
|
for (let i = 0; i < html_files.length; i++) {
|
@@ -268,7 +289,7 @@
|
|
268
289
|
warnings[html_files[i].relativePath] = [];
|
269
290
|
|
270
291
|
// Check for Britishisms
|
271
|
-
await checkBritishSpellings(html_files[i]);
|
292
|
+
await checkBritishSpellings(html_files[i], exclude_spellcheck);
|
272
293
|
|
273
294
|
const links = getLinks(html_files[i]);
|
274
295
|
if (links.href.length === 0) {
|