hdoc-tools 0.37.0 → 0.39.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-build.js +2 -1
- package/hdoc-validate.js +35 -4
- package/hdoc.js +37 -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]);
|
@@ -488,6 +508,9 @@ const e = require("express");
|
|
488
508
|
errors[htmlFile.relativePath].push(error_message);
|
489
509
|
}
|
490
510
|
} else {
|
511
|
+
if (links[i] === 'http://www.idontexistasawebsite.co.uk') {
|
512
|
+
console.log(`Checking for a dummy link: ${links[i]}`);
|
513
|
+
}
|
491
514
|
messages[htmlFile.relativePath].push(
|
492
515
|
`Link is a properly formatted external URL: ${links[i]}`,
|
493
516
|
);
|
@@ -503,10 +526,12 @@ const e = require("express");
|
|
503
526
|
)
|
504
527
|
.edit_path.replace(path.extname(htmlFile.relativePath), ".md")
|
505
528
|
) {
|
529
|
+
fs.appendFileSync(skip_link_file, `${links[i]}\n`);
|
506
530
|
continue;
|
507
531
|
}
|
508
532
|
|
509
533
|
if (valid_url.protocol === "mailto:") {
|
534
|
+
fs.appendFileSync(skip_link_file, `${links[i]}\n`);
|
510
535
|
continue;
|
511
536
|
}
|
512
537
|
|
@@ -525,6 +550,7 @@ const e = require("express");
|
|
525
550
|
messages[htmlFile.relativePath].push(
|
526
551
|
`Outside of Hornbill network - skipping internal link validation for: ${links[i]}`,
|
527
552
|
);
|
553
|
+
fs.appendFileSync(skip_link_file, `${links[i]}\n`);
|
528
554
|
continue;
|
529
555
|
}
|
530
556
|
messages[htmlFile.relativePath].push(
|
@@ -564,14 +590,11 @@ const e = require("express");
|
|
564
590
|
|
565
591
|
|
566
592
|
try {
|
567
|
-
|
568
593
|
// Set a user-agent to mimic a real browser
|
569
594
|
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
595
|
|
571
596
|
try {
|
572
597
|
let response = null;
|
573
|
-
let lastRedirectStatus = null;
|
574
|
-
let redirectChain = [];
|
575
598
|
|
576
599
|
// Capture redirects and final response
|
577
600
|
page.on('request', (request) => {
|
@@ -595,6 +618,7 @@ const e = require("express");
|
|
595
618
|
});
|
596
619
|
|
597
620
|
if (response) {
|
621
|
+
console.log(response);
|
598
622
|
let status = response.status();
|
599
623
|
const contentType = response.headers()['content-type'];
|
600
624
|
|
@@ -612,12 +636,15 @@ const e = require("express");
|
|
612
636
|
} else {
|
613
637
|
throw `Unexpected Status Returned: ${status}`;
|
614
638
|
}
|
639
|
+
} else {
|
640
|
+
fs.appendFileSync(skip_link_file, `${links[i]}\n`);
|
615
641
|
}
|
642
|
+
} else {
|
643
|
+
throw `No response from: ${links[i]}`;
|
616
644
|
}
|
617
645
|
} catch (error) {
|
618
646
|
throw error;
|
619
647
|
}
|
620
|
-
|
621
648
|
} catch (e) {
|
622
649
|
let error_message;
|
623
650
|
if (e instanceof AggregateError) {
|
@@ -883,11 +910,15 @@ const e = require("express");
|
|
883
910
|
draft_links,
|
884
911
|
is_private,
|
885
912
|
browser,
|
913
|
+
source_root_path,
|
886
914
|
) => {
|
887
915
|
console.log("Performing Validation and Building SEO Link List...");
|
888
916
|
redirects = gen_redirects;
|
889
917
|
private_repo = is_private;
|
890
918
|
|
919
|
+
// Load the skip link validation file if it exists
|
920
|
+
loadSkipLinkValidation(source_root_path);
|
921
|
+
|
891
922
|
// Get a list of HTML files in source_path
|
892
923
|
dree.scan(source_path, dreeOptions, fileContentCallback);
|
893
924
|
|
package/hdoc.js
CHANGED
@@ -7,6 +7,32 @@
|
|
7
7
|
|
8
8
|
const packageFile = path.join(__dirname, "package.json");
|
9
9
|
|
10
|
+
const originalConsoleLog = console.log;
|
11
|
+
|
12
|
+
console.log = (...args) => {
|
13
|
+
if (process.env.GITHUB_ACTIONS !== 'true') {
|
14
|
+
// If not running in GitHub Actions, send args to the original console.log
|
15
|
+
originalConsoleLog(...args);
|
16
|
+
|
17
|
+
} else {
|
18
|
+
// If running in GitHub Actions, escape % and \ characters so printf doesn't throw an error
|
19
|
+
const escapedArgs = args.map(arg => {
|
20
|
+
if (typeof arg === 'string') {
|
21
|
+
return arg.replace(/%/g, '%%').replace(/\\/g, '\\\\');
|
22
|
+
}
|
23
|
+
return arg;
|
24
|
+
});
|
25
|
+
// Use the original console.log with escaped arguments
|
26
|
+
originalConsoleLog(...escapedArgs);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
if (process.env.GITHUB_ACTIONS === 'true') {
|
31
|
+
console.log("\nRunning in GitHub Actions environment\n");
|
32
|
+
} else {
|
33
|
+
console.log("\nRunning in non-GitHub Actions environment\n");
|
34
|
+
}
|
35
|
+
|
10
36
|
let console_color = true;
|
11
37
|
|
12
38
|
const { info, error } = console;
|
@@ -103,6 +129,17 @@
|
|
103
129
|
console.log(" Server Path:", __dirname);
|
104
130
|
console.log(" Document Path:", source_path, "\r\n");
|
105
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
|
+
|
106
143
|
if (command.toLowerCase() === "serve") {
|
107
144
|
const server = require(path.join(__dirname, "hdoc-serve.js"));
|
108
145
|
server.run(ui_path, source_path);
|
package/package.json
CHANGED
package/templates/init/gitignore
CHANGED