hdoc-tools 0.25.1 → 0.26.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 +42 -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,12 @@ 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().endsWith(".hornbill.com") &&
|
535
|
+
!links[i].toLowerCase().endsWith(".hornbill.com/")
|
511
536
|
) {
|
512
537
|
const error_message = processErrorMessage(`Hornbill Docs links should not be fully-qualified: ${links[i]}`, markdown_paths.relativePath, markdown_content, links[i]);
|
513
538
|
errors[htmlFile.relativePath].push( error_message );
|
@@ -535,6 +560,18 @@ const e = require("express");
|
|
535
560
|
}
|
536
561
|
};
|
537
562
|
|
563
|
+
const checkHostExistsInDNS = async (hostname) => {
|
564
|
+
return new Promise((resolve, reject) => {
|
565
|
+
dns.lookup(hostname, { all:true }, (err, addresses) => {
|
566
|
+
if (err) {
|
567
|
+
reject(err);
|
568
|
+
} else {
|
569
|
+
resolve(addresses !== undefined);
|
570
|
+
}
|
571
|
+
});
|
572
|
+
});
|
573
|
+
}
|
574
|
+
|
538
575
|
const checkImages = async (source_path, htmlFile, links) => {
|
539
576
|
const markdown_paths = getMDPathFromHtmlPath(htmlFile);
|
540
577
|
const markdown_content = fs.readFileSync(markdown_paths.markdownPath, 'utf8');
|
@@ -900,7 +937,6 @@ const e = require("express");
|
|
900
937
|
);
|
901
938
|
|
902
939
|
// Perform rest of validation against HTML files
|
903
|
-
let listContent = "";
|
904
940
|
const htmlPromiseArray = [];
|
905
941
|
for (let i = 0; i < html_to_validate.length; i++) {
|
906
942
|
errors[html_to_validate[i].relativePath] = [];
|
@@ -941,24 +977,11 @@ const e = require("express");
|
|
941
977
|
|
942
978
|
// Check for multiple H1 tags
|
943
979
|
await checkTags(file);
|
944
|
-
|
945
|
-
// Build list content for Google
|
946
|
-
listContent += `/${file.relativePath.replace(path.extname(file.relativePath), "")}`;
|
947
|
-
listContent += "\r\n";
|
948
980
|
}),
|
949
981
|
);
|
950
982
|
|
951
983
|
if (gen_exclude) console.log(JSON.stringify(excl_output, null, 2));
|
952
984
|
|
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
985
|
if (verbose) {
|
963
986
|
console.log("\r\n-------------");
|
964
987
|
console.log(" Verbose ");
|