hdoc-tools 0.9.1 → 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 +40 -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
|
|
@@ -74,6 +90,10 @@
|
|
74
90
|
const valid_url = hdoc.valid_url(links[i]);
|
75
91
|
if (!valid_url) {
|
76
92
|
// Could be a relative path, check
|
93
|
+
if (links[i].startsWith('/')) {
|
94
|
+
const link_root = links[i].split('/')[0];
|
95
|
+
if (link_root !== hdocbook_config.docId) continue;
|
96
|
+
}
|
77
97
|
isRelativePath(source_path, htmlFile, links[i]);
|
78
98
|
} else {
|
79
99
|
messages[htmlFile.relativePath].push(`Link is a properly formatted external URL: ${links[i]}`);
|
@@ -222,7 +242,7 @@
|
|
222
242
|
return links;
|
223
243
|
};
|
224
244
|
|
225
|
-
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) {
|
226
246
|
console.log(`Performing Validation and Building SEO Link List...`);
|
227
247
|
|
228
248
|
// Load product families
|
@@ -244,16 +264,21 @@
|
|
244
264
|
console.log('-----------------------\r\n');
|
245
265
|
console.log(`- Incorrect productFamily: ${hdocbook_config.productFamily}`)
|
246
266
|
console.log(`\r\n1 Validation Errors Found\r\n`);
|
247
|
-
console.log(``)
|
248
267
|
return false;
|
249
268
|
}
|
250
269
|
|
251
|
-
if (hdocbook_project.validation
|
252
|
-
hdocbook_project.validation.exclude_links.
|
253
|
-
|
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;
|
254
279
|
});
|
255
280
|
}
|
256
|
-
|
281
|
+
}
|
257
282
|
|
258
283
|
let listContent = '';
|
259
284
|
for (let i = 0; i < html_files.length; i++) {
|
@@ -264,7 +289,7 @@
|
|
264
289
|
warnings[html_files[i].relativePath] = [];
|
265
290
|
|
266
291
|
// Check for Britishisms
|
267
|
-
await checkBritishSpellings(html_files[i]);
|
292
|
+
await checkBritishSpellings(html_files[i], exclude_spellcheck);
|
268
293
|
|
269
294
|
const links = getLinks(html_files[i]);
|
270
295
|
if (links.href.length === 0) {
|