hdoc-tools 0.25.1 → 0.26.1
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 +44 -19
- package/package.json +1 -1
package/hdoc-validate.js
CHANGED
@@ -4,6 +4,7 @@ const e = require("express");
|
|
4
4
|
const axios = require("axios");
|
5
5
|
const cheerio = require("cheerio");
|
6
6
|
const dree = require("dree");
|
7
|
+
const dns = require("node:dns");
|
7
8
|
const fs = require("node:fs");
|
8
9
|
const path = require("node:path");
|
9
10
|
const https = require("node:https");
|
@@ -494,7 +495,29 @@ const e = require("express");
|
|
494
495
|
if (valid_url.protocol === "mailto:") {
|
495
496
|
continue;
|
496
497
|
}
|
497
|
-
|
498
|
+
|
499
|
+
// Skip internal.hornbill.com link validation if run outside of the Hornbill network
|
500
|
+
if (links[i].toLowerCase().includes(".internal.hornbill.com")) {
|
501
|
+
// DNS lookup internal docs endpoint
|
502
|
+
const hostname = 'docs-internal.hornbill.com';
|
503
|
+
let on_int_net = false;
|
504
|
+
try {
|
505
|
+
on_int_net = await checkHostExistsInDNS(hostname);
|
506
|
+
} catch (e) {
|
507
|
+
// Don't need to do anything here
|
508
|
+
}
|
509
|
+
|
510
|
+
if (!on_int_net) {
|
511
|
+
messages[htmlFile.relativePath].push(
|
512
|
+
`Outside of Hornbill network - skipping internal link validation for: ${links[i]}`,
|
513
|
+
);
|
514
|
+
continue;
|
515
|
+
}
|
516
|
+
messages[htmlFile.relativePath].push(
|
517
|
+
`Inside of Hornbill network - performing internal link validation for: ${links[i]}`,
|
518
|
+
);
|
519
|
+
}
|
520
|
+
|
498
521
|
// Skip if the link is excluded in the project config
|
499
522
|
const skip_link = await excludeLink(links[i]);
|
500
523
|
if (skip_link) {
|
@@ -504,10 +527,14 @@ const e = require("express");
|
|
504
527
|
continue;
|
505
528
|
}
|
506
529
|
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
530
|
+
if (
|
531
|
+
( links[i].toLowerCase().includes("docs.hornbill.com") ||
|
532
|
+
links[i].toLowerCase().includes("docs-internal.hornbill.com")
|
533
|
+
) &&
|
534
|
+
links[i].toLowerCase() !== ("https://docs-internal.hornbill.com/") &&
|
535
|
+
links[i].toLowerCase() !== ("https://docs-internal.hornbill.com") &&
|
536
|
+
links[i].toLowerCase() !== ("https://docs.hornbill.com/") &&
|
537
|
+
links[i].toLowerCase() !== ("https://docs.hornbill.com")
|
511
538
|
) {
|
512
539
|
const error_message = processErrorMessage(`Hornbill Docs links should not be fully-qualified: ${links[i]}`, markdown_paths.relativePath, markdown_content, links[i]);
|
513
540
|
errors[htmlFile.relativePath].push( error_message );
|
@@ -535,6 +562,18 @@ const e = require("express");
|
|
535
562
|
}
|
536
563
|
};
|
537
564
|
|
565
|
+
const checkHostExistsInDNS = async (hostname) => {
|
566
|
+
return new Promise((resolve, reject) => {
|
567
|
+
dns.lookup(hostname, { all:true }, (err, addresses) => {
|
568
|
+
if (err) {
|
569
|
+
reject(err);
|
570
|
+
} else {
|
571
|
+
resolve(addresses !== undefined);
|
572
|
+
}
|
573
|
+
});
|
574
|
+
});
|
575
|
+
}
|
576
|
+
|
538
577
|
const checkImages = async (source_path, htmlFile, links) => {
|
539
578
|
const markdown_paths = getMDPathFromHtmlPath(htmlFile);
|
540
579
|
const markdown_content = fs.readFileSync(markdown_paths.markdownPath, 'utf8');
|
@@ -900,7 +939,6 @@ const e = require("express");
|
|
900
939
|
);
|
901
940
|
|
902
941
|
// Perform rest of validation against HTML files
|
903
|
-
let listContent = "";
|
904
942
|
const htmlPromiseArray = [];
|
905
943
|
for (let i = 0; i < html_to_validate.length; i++) {
|
906
944
|
errors[html_to_validate[i].relativePath] = [];
|
@@ -941,24 +979,11 @@ const e = require("express");
|
|
941
979
|
|
942
980
|
// Check for multiple H1 tags
|
943
981
|
await checkTags(file);
|
944
|
-
|
945
|
-
// Build list content for Google
|
946
|
-
listContent += `/${file.relativePath.replace(path.extname(file.relativePath), "")}`;
|
947
|
-
listContent += "\r\n";
|
948
982
|
}),
|
949
983
|
);
|
950
984
|
|
951
985
|
if (gen_exclude) console.log(JSON.stringify(excl_output, null, 2));
|
952
986
|
|
953
|
-
try {
|
954
|
-
// Write list
|
955
|
-
const listFile = path.join(source_path, doc_id, "links.txt");
|
956
|
-
fs.writeFileSync(listFile, listContent);
|
957
|
-
console.log(`\r\nLink list text file created successfully: ${listFile}`);
|
958
|
-
} catch (err) {
|
959
|
-
console.error(err);
|
960
|
-
}
|
961
|
-
|
962
987
|
if (verbose) {
|
963
988
|
console.log("\r\n-------------");
|
964
989
|
console.log(" Verbose ");
|