hdoc-tools 0.36.1 → 0.37.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-validate.js +46 -40
- package/package.json +1 -1
package/hdoc-validate.js
CHANGED
@@ -448,12 +448,18 @@ const e = require("express");
|
|
448
448
|
return returnPaths;
|
449
449
|
}
|
450
450
|
|
451
|
-
const checkLinks = async (source_path, htmlFile, links, hdocbook_config, hdocbook_project, browser) => {
|
451
|
+
const checkLinks = async (source_path, htmlFile, links, hdocbook_config, hdocbook_project, browser, global_links_checked) => {
|
452
452
|
const markdown_paths = getMDPathFromHtmlPath(htmlFile);
|
453
453
|
const markdown_content = fs.readFileSync(markdown_paths.markdownPath, 'utf8');
|
454
454
|
|
455
|
+
// Use Puppeteer to validate link address works
|
456
|
+
const page = await browser.newPage();
|
457
|
+
|
455
458
|
for (let i = 0; i < links.length; i++) {
|
456
459
|
// Validate that link is a valid URL first
|
460
|
+
console.log(` - ${links[i]}`);
|
461
|
+
if (global_links_checked.includes(links[i])) continue;
|
462
|
+
global_links_checked.push(links[i]);
|
457
463
|
const valid_url = hdoc.valid_url(links[i]);
|
458
464
|
if (!valid_url) {
|
459
465
|
// Could be a relative path, check
|
@@ -559,9 +565,6 @@ const e = require("express");
|
|
559
565
|
|
560
566
|
try {
|
561
567
|
|
562
|
-
// Use Puppeteer to validate link address works
|
563
|
-
const page = await browser.newPage();
|
564
|
-
|
565
568
|
// Set a user-agent to mimic a real browser
|
566
569
|
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36');
|
567
570
|
|
@@ -615,9 +618,6 @@ const e = require("express");
|
|
615
618
|
throw error;
|
616
619
|
}
|
617
620
|
|
618
|
-
// Close the headless browser tab
|
619
|
-
page.close();
|
620
|
-
|
621
621
|
} catch (e) {
|
622
622
|
let error_message;
|
623
623
|
if (e instanceof AggregateError) {
|
@@ -633,6 +633,8 @@ const e = require("express");
|
|
633
633
|
}
|
634
634
|
}
|
635
635
|
}
|
636
|
+
// Close the headless browser tab
|
637
|
+
page.close();
|
636
638
|
};
|
637
639
|
|
638
640
|
const checkHostExistsInDNS = async (hostname) => {
|
@@ -1028,42 +1030,46 @@ const e = require("express");
|
|
1028
1030
|
warnings[html_to_validate[i].relativePath] = [];
|
1029
1031
|
htmlPromiseArray.push(html_to_validate[i]);
|
1030
1032
|
}
|
1031
|
-
await Promise.all(
|
1032
|
-
htmlPromiseArray.map(async (file) => {
|
1033
|
-
// Check for British spellings in static HTML content
|
1034
|
-
if (
|
1035
|
-
!md_files_spellchecked[
|
1036
|
-
file.relativePath.replace(`.${file.extension}`, "")
|
1037
|
-
]
|
1038
|
-
) {
|
1039
|
-
const exclusions = await spellcheckContent(file, exclude_spellcheck);
|
1040
|
-
if (gen_exclude && exclusions.length > 0)
|
1041
|
-
excl_output.push({
|
1042
|
-
document_path: file.relativePath.replace(
|
1043
|
-
`.${file.extension}`,
|
1044
|
-
"",
|
1045
|
-
),
|
1046
|
-
words: exclusions,
|
1047
|
-
});
|
1048
|
-
}
|
1049
1033
|
|
1050
|
-
|
1051
|
-
|
1052
|
-
messages[file.relativePath].push("No links found in file");
|
1053
|
-
} else {
|
1054
|
-
await checkLinks(source_path, file, links.href, hdocbook_config, hdocbook_project, browser);
|
1055
|
-
}
|
1056
|
-
if (links.img.length === 0) {
|
1057
|
-
messages[file.relativePath].push("No images found in file");
|
1058
|
-
} else {
|
1059
|
-
await checkImages(source_path, file, links.img);
|
1060
|
-
}
|
1034
|
+
|
1035
|
+
const global_links_checked = [];
|
1061
1036
|
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1037
|
+
for (const key in html_to_validate) {
|
1038
|
+
const file = html_to_validate[key];
|
1039
|
+
// Check for British spellings in static HTML content
|
1040
|
+
if (
|
1041
|
+
!md_files_spellchecked[
|
1042
|
+
file.relativePath.replace(`.${file.extension}`, "")
|
1043
|
+
]
|
1044
|
+
) {
|
1045
|
+
const exclusions = await spellcheckContent(file, exclude_spellcheck);
|
1046
|
+
if (gen_exclude && exclusions.length > 0)
|
1047
|
+
excl_output.push({
|
1048
|
+
document_path: file.relativePath.replace(
|
1049
|
+
`.${file.extension}`,
|
1050
|
+
"",
|
1051
|
+
),
|
1052
|
+
words: exclusions,
|
1053
|
+
});
|
1054
|
+
}
|
1066
1055
|
|
1056
|
+
const links = getLinks(file);
|
1057
|
+
if (links.href.length === 0) {
|
1058
|
+
messages[file.relativePath].push("No links found in file");
|
1059
|
+
} else {
|
1060
|
+
console.log(`\r\nChecking Links in ${file.relativePath}`);
|
1061
|
+
await checkLinks(source_path, file, links.href, hdocbook_config, hdocbook_project, browser, global_links_checked);
|
1062
|
+
}
|
1063
|
+
if (links.img.length === 0) {
|
1064
|
+
messages[file.relativePath].push("No images found in file");
|
1065
|
+
} else {
|
1066
|
+
await checkImages(source_path, file, links.img);
|
1067
|
+
}
|
1068
|
+
|
1069
|
+
// Check for multiple H1 tags
|
1070
|
+
await checkTags(file);
|
1071
|
+
}
|
1072
|
+
|
1067
1073
|
if (gen_exclude) console.log(JSON.stringify(excl_output, null, 2));
|
1068
1074
|
|
1069
1075
|
if (verbose) {
|