hdoc-tools 0.38.0 → 0.39.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-build.js +2 -1
- package/hdoc-validate.js +31 -4
- package/hdoc.js +11 -0
- package/package.json +1 -1
- package/templates/init/gitignore +2 -1
package/hdoc-build.js
CHANGED
@@ -1410,7 +1410,8 @@
|
|
1410
1410
|
redirects,
|
1411
1411
|
draft_links,
|
1412
1412
|
github_repo_details && github_repo_details.data && github_repo_details.data.private ? github_repo_details.data.private : false,
|
1413
|
-
browser
|
1413
|
+
browser,
|
1414
|
+
source_path
|
1414
1415
|
);
|
1415
1416
|
|
1416
1417
|
// Close the Chromium browser instance
|
package/hdoc-validate.js
CHANGED
@@ -26,6 +26,7 @@ const e = require("express");
|
|
26
26
|
const exclude_spellcheck = {};
|
27
27
|
let private_repo = false;
|
28
28
|
let redirects = {};
|
29
|
+
let skip_link_file = '';
|
29
30
|
const exclude_h1_count = {};
|
30
31
|
const exclude_spellcheck_output = [];
|
31
32
|
|
@@ -42,6 +43,23 @@ const e = require("express");
|
|
42
43
|
return false;
|
43
44
|
};
|
44
45
|
|
46
|
+
const loadSkipLinkValidation = (source_path) => {
|
47
|
+
skip_link_file = path.join(source_path, "validated-links.txt");
|
48
|
+
if (fs.existsSync(skip_link_file)) {
|
49
|
+
console.log(`Loading skip link validation file from: ${skip_link_file}`);
|
50
|
+
const skip_links = fs.readFileSync(skip_link_file, "utf8").split("\n");
|
51
|
+
for (let i = 0; i < skip_links.length; i++) {
|
52
|
+
if (skip_links[i].trim() !== "") {
|
53
|
+
exclude_links[skip_links[i].trim()] = true;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
} else {
|
57
|
+
//Create the file if it doesn't exist
|
58
|
+
console.log(`Creating skip link validation file: ${skip_link_file}`);
|
59
|
+
fs.writeFileSync(skip_link_file, "", "utf8");
|
60
|
+
}
|
61
|
+
};
|
62
|
+
|
45
63
|
const spellcheckContent = async (sourceFile, excludes) => {
|
46
64
|
const spelling_errors = {};
|
47
65
|
const words = [];
|
@@ -457,6 +475,7 @@ const e = require("express");
|
|
457
475
|
|
458
476
|
for (let i = 0; i < links.length; i++) {
|
459
477
|
// Validate that link is a valid URL first
|
478
|
+
if (exclude_links[links[i]]) continue;
|
460
479
|
console.log(` - ${links[i]}`);
|
461
480
|
if (global_links_checked.includes(links[i])) continue;
|
462
481
|
global_links_checked.push(links[i]);
|
@@ -477,6 +496,7 @@ const e = require("express");
|
|
477
496
|
|
478
497
|
// Checking for internal links in other books - can't easily validate those here, returning
|
479
498
|
if (link_segments.length > 1 && link_root !== hdocbook_config.docId) {
|
499
|
+
fs.appendFileSync(skip_link_file, `${links[i]}\n`);
|
480
500
|
continue;
|
481
501
|
}
|
482
502
|
isRelativePath(source_path, htmlFile, links[i]);
|
@@ -503,10 +523,12 @@ const e = require("express");
|
|
503
523
|
)
|
504
524
|
.edit_path.replace(path.extname(htmlFile.relativePath), ".md")
|
505
525
|
) {
|
526
|
+
fs.appendFileSync(skip_link_file, `${links[i]}\n`);
|
506
527
|
continue;
|
507
528
|
}
|
508
529
|
|
509
530
|
if (valid_url.protocol === "mailto:") {
|
531
|
+
fs.appendFileSync(skip_link_file, `${links[i]}\n`);
|
510
532
|
continue;
|
511
533
|
}
|
512
534
|
|
@@ -525,6 +547,7 @@ const e = require("express");
|
|
525
547
|
messages[htmlFile.relativePath].push(
|
526
548
|
`Outside of Hornbill network - skipping internal link validation for: ${links[i]}`,
|
527
549
|
);
|
550
|
+
fs.appendFileSync(skip_link_file, `${links[i]}\n`);
|
528
551
|
continue;
|
529
552
|
}
|
530
553
|
messages[htmlFile.relativePath].push(
|
@@ -564,14 +587,11 @@ const e = require("express");
|
|
564
587
|
|
565
588
|
|
566
589
|
try {
|
567
|
-
|
568
590
|
// Set a user-agent to mimic a real browser
|
569
591
|
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');
|
570
592
|
|
571
593
|
try {
|
572
594
|
let response = null;
|
573
|
-
let lastRedirectStatus = null;
|
574
|
-
let redirectChain = [];
|
575
595
|
|
576
596
|
// Capture redirects and final response
|
577
597
|
page.on('request', (request) => {
|
@@ -612,12 +632,15 @@ const e = require("express");
|
|
612
632
|
} else {
|
613
633
|
throw `Unexpected Status Returned: ${status}`;
|
614
634
|
}
|
635
|
+
} else {
|
636
|
+
fs.appendFileSync(skip_link_file, `${links[i]}\n`);
|
615
637
|
}
|
638
|
+
} else {
|
639
|
+
throw `No response from: ${links[i]}`;
|
616
640
|
}
|
617
641
|
} catch (error) {
|
618
642
|
throw error;
|
619
643
|
}
|
620
|
-
|
621
644
|
} catch (e) {
|
622
645
|
let error_message;
|
623
646
|
if (e instanceof AggregateError) {
|
@@ -883,11 +906,15 @@ const e = require("express");
|
|
883
906
|
draft_links,
|
884
907
|
is_private,
|
885
908
|
browser,
|
909
|
+
source_root_path,
|
886
910
|
) => {
|
887
911
|
console.log("Performing Validation and Building SEO Link List...");
|
888
912
|
redirects = gen_redirects;
|
889
913
|
private_repo = is_private;
|
890
914
|
|
915
|
+
// Load the skip link validation file if it exists
|
916
|
+
loadSkipLinkValidation(source_root_path);
|
917
|
+
|
891
918
|
// Get a list of HTML files in source_path
|
892
919
|
dree.scan(source_path, dreeOptions, fileContentCallback);
|
893
920
|
|
package/hdoc.js
CHANGED
@@ -129,6 +129,17 @@
|
|
129
129
|
console.log(" Server Path:", __dirname);
|
130
130
|
console.log(" Document Path:", source_path, "\r\n");
|
131
131
|
|
132
|
+
|
133
|
+
// Add validated-links.txt to .gitignore if it doesn't exist
|
134
|
+
const gitignorePath = path.join(source_path, ".gitignore");
|
135
|
+
if (fs.existsSync(gitignorePath)) {
|
136
|
+
const gitignoreContent = fs.readFileSync(gitignorePath, "utf8");
|
137
|
+
if (!gitignoreContent.includes("validated-links.txt")) {
|
138
|
+
fs.appendFileSync(gitignorePath, "\nvalidated-links.txt\n");
|
139
|
+
console.info("Added validated-links.txt to .gitignore");
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
132
143
|
if (command.toLowerCase() === "serve") {
|
133
144
|
const server = require(path.join(__dirname, "hdoc-serve.js"));
|
134
145
|
server.run(ui_path, source_path);
|
package/package.json
CHANGED
package/templates/init/gitignore
CHANGED