hdoc-tools 0.28.0 → 0.29.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 +11 -6
- package/package.json +1 -1
package/hdoc-validate.js
CHANGED
|
@@ -458,15 +458,14 @@ const e = require("express");
|
|
|
458
458
|
if (!valid_url) {
|
|
459
459
|
// Could be a relative path, check
|
|
460
460
|
if (links[i].startsWith("/") && !links[i].startsWith("/#")) {
|
|
461
|
-
let
|
|
462
|
-
if (
|
|
463
|
-
link_root =
|
|
461
|
+
let link_segments = links[i].split("/");
|
|
462
|
+
if (link_segments[0] === "") link_segments.shift();
|
|
463
|
+
const link_root = link_segments[0] === "_books" ? link_segments[1] : link_segments[0];
|
|
464
464
|
|
|
465
465
|
// Checking for internal links in other books - can't easily validate those here, returning
|
|
466
|
-
if (link_root !== hdocbook_config.docId) {
|
|
466
|
+
if (link_segments.length > 1 && link_root !== hdocbook_config.docId) {
|
|
467
467
|
continue;
|
|
468
468
|
}
|
|
469
|
-
|
|
470
469
|
isRelativePath(source_path, htmlFile, links[i]);
|
|
471
470
|
} else if (links[i].startsWith("#") || links[i].startsWith("/#")) {
|
|
472
471
|
//Flat Anchor - validate we have a same-file hit
|
|
@@ -543,7 +542,7 @@ const e = require("express");
|
|
|
543
542
|
url: links[i],
|
|
544
543
|
method: 'get',
|
|
545
544
|
timeout: 10000,
|
|
546
|
-
maxRedirects:
|
|
545
|
+
maxRedirects: 5,
|
|
547
546
|
validateStatus: (status) =>
|
|
548
547
|
status >= 200 && status < 400,
|
|
549
548
|
})
|
|
@@ -577,6 +576,12 @@ const e = require("express");
|
|
|
577
576
|
for (let i = 0; i < links.length; i++) {
|
|
578
577
|
// Validate that image is a valid URL first
|
|
579
578
|
if (!hdoc.valid_url(links[i])) {
|
|
579
|
+
|
|
580
|
+
if (!links[i].startsWith("/")) {
|
|
581
|
+
const error_message = processErrorMessage(`Root relative image links should start with a forward-slash: ${links[i]}`, markdown_paths.relativePath, markdown_content, links[i]);
|
|
582
|
+
errors[htmlFile.relativePath].push(error_message);
|
|
583
|
+
}
|
|
584
|
+
|
|
580
585
|
// Could be a relative path, check image exists
|
|
581
586
|
doesFileExist(source_path, htmlFile, links[i], markdown_paths.relativePath, markdown_content);
|
|
582
587
|
} else {
|