hdoc-tools 0.9.2 → 0.9.4
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 +39 -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,17 @@
|
|
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
|
+
selectors: [
|
83
|
+
{ selector: 'code', format: 'skip'}
|
84
|
+
]
|
85
|
+
});
|
86
|
+
checkBritishSpelling(htmlFile.path, excludes, text);
|
87
|
+
};
|
88
|
+
|
70
89
|
const checkLinks = async function (source_path, htmlFile, links, hdocbook_config) {
|
71
90
|
for (let i = 0; i < links.length; i++) {
|
72
91
|
|
@@ -226,7 +245,7 @@
|
|
226
245
|
return links;
|
227
246
|
};
|
228
247
|
|
229
|
-
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project) {
|
248
|
+
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items) {
|
230
249
|
console.log(`Performing Validation and Building SEO Link List...`);
|
231
250
|
|
232
251
|
// Load product families
|
@@ -248,16 +267,21 @@
|
|
248
267
|
console.log('-----------------------\r\n');
|
249
268
|
console.log(`- Incorrect productFamily: ${hdocbook_config.productFamily}`)
|
250
269
|
console.log(`\r\n1 Validation Errors Found\r\n`);
|
251
|
-
console.log(``)
|
252
270
|
return false;
|
253
271
|
}
|
254
272
|
|
255
|
-
if (hdocbook_project.validation
|
256
|
-
hdocbook_project.validation.exclude_links.
|
257
|
-
|
273
|
+
if (hdocbook_project.validation) {
|
274
|
+
if (hdocbook_project.validation.exclude_links && hdocbook_project.validation.exclude_links instanceof Array) {
|
275
|
+
hdocbook_project.validation.exclude_links.forEach(function(excl_link) {
|
276
|
+
exclude_links[excl_link] = true;
|
277
|
+
});
|
278
|
+
}
|
279
|
+
if (hdocbook_project.validation.exclude_spellcheck && hdocbook_project.validation.exclude_spellcheck instanceof Array) {
|
280
|
+
hdocbook_project.validation.exclude_spellcheck.forEach(function(excl_sc) {
|
281
|
+
exclude_spellcheck[excl_sc.document_path] = excl_sc.words;
|
258
282
|
});
|
259
283
|
}
|
260
|
-
|
284
|
+
}
|
261
285
|
|
262
286
|
let listContent = '';
|
263
287
|
for (let i = 0; i < html_files.length; i++) {
|
@@ -268,7 +292,7 @@
|
|
268
292
|
warnings[html_files[i].relativePath] = [];
|
269
293
|
|
270
294
|
// Check for Britishisms
|
271
|
-
await checkBritishSpellings(html_files[i]);
|
295
|
+
await checkBritishSpellings(html_files[i], exclude_spellcheck);
|
272
296
|
|
273
297
|
const links = getLinks(html_files[i]);
|
274
298
|
if (links.href.length === 0) {
|