hdoc-tools 0.24.1 → 0.25.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-module.js +10 -2
- package/hdoc-validate.js +36 -24
- package/package.json +1 -1
package/hdoc-module.js
CHANGED
@@ -20,8 +20,16 @@
|
|
20
20
|
axiosRetry(axios, {
|
21
21
|
retries: 5,
|
22
22
|
shouldResetTimeout: true,
|
23
|
-
retryCondition
|
24
|
-
|
23
|
+
retryCondition(error) {
|
24
|
+
if (error.response && error.response.status) {
|
25
|
+
if (error.response.status >= 400 && error.response.status !== 401 && error.response.status !== 403) {
|
26
|
+
return true;
|
27
|
+
} else {
|
28
|
+
return false;
|
29
|
+
}
|
30
|
+
} else {
|
31
|
+
return false;
|
32
|
+
}
|
25
33
|
},
|
26
34
|
onRetry: (retryCount, error, requestConfig) => {
|
27
35
|
retried = true;
|
package/hdoc-validate.js
CHANGED
@@ -53,7 +53,8 @@ const e = require("express");
|
|
53
53
|
"",
|
54
54
|
);
|
55
55
|
|
56
|
-
const
|
56
|
+
const markdown_paths = getMDPathFromHtmlPath(sourceFile);
|
57
|
+
|
57
58
|
const translate_output = translator.translate(text, spellcheck_options);
|
58
59
|
if (Object.keys(translate_output).length) {
|
59
60
|
for (const key in translate_output) {
|
@@ -68,9 +69,9 @@ const e = require("express");
|
|
68
69
|
) {
|
69
70
|
const link_location = hdoc.find_string_in_string(text.split('\n')[key - 1], spelling);
|
70
71
|
if (link_location !== null)
|
71
|
-
error_message = `${
|
72
|
+
error_message = `${markdown_paths.relativePath}:${key}:${link_location.column} - ${error_message}`;
|
72
73
|
else
|
73
|
-
error_message = `${
|
74
|
+
error_message = `${markdown_paths.relativePath}:${key} - ${error_message}`;
|
74
75
|
if (!excludes[source_path]) {
|
75
76
|
errors[sourceFile.relativePath].push(
|
76
77
|
`${error_message} ${spelling} should be ${translate_output[key][i][spelling].details}`,
|
@@ -433,17 +434,20 @@ const e = require("express");
|
|
433
434
|
};
|
434
435
|
|
435
436
|
const getMDPathFromHtmlPath = (htmlFile) => {
|
436
|
-
const
|
437
|
-
|
437
|
+
const returnPaths = {
|
438
|
+
markdownPath: htmlFile.path.replace(`.${htmlFile.extension}`, '.md'),
|
439
|
+
relativePath: htmlFile.relativePath.replace(`.${htmlFile.extension}`, '.md')
|
440
|
+
};
|
441
|
+
if (!fs.existsSync(returnPaths.markdownPath)) {
|
438
442
|
// No matching markdown
|
439
|
-
|
443
|
+
returnPaths.markdownPath = htmlFile.path;
|
440
444
|
}
|
441
|
-
return
|
445
|
+
return returnPaths;
|
442
446
|
}
|
443
447
|
|
444
448
|
const checkLinks = async (source_path, htmlFile, links, hdocbook_config) => {
|
445
|
-
const
|
446
|
-
const markdown_content = fs.readFileSync(
|
449
|
+
const markdown_paths = getMDPathFromHtmlPath(htmlFile);
|
450
|
+
const markdown_content = fs.readFileSync(markdown_paths.markdownPath, 'utf8');
|
447
451
|
|
448
452
|
for (let i = 0; i < links.length; i++) {
|
449
453
|
// Validate that link is a valid URL first
|
@@ -465,7 +469,7 @@ const e = require("express");
|
|
465
469
|
//Flat Anchor - validate we have a same-file hit
|
466
470
|
isHashAnchor(htmlFile, links[i]);
|
467
471
|
} else {
|
468
|
-
const error_message = processErrorMessage(`Root relative links should start with a forward-slash: ${links[i]}`,
|
472
|
+
const error_message = processErrorMessage(`Root relative links should start with a forward-slash: ${links[i]}`, markdown_paths.relativePath, markdown_content, links[i]);
|
469
473
|
errors[htmlFile.relativePath].push(error_message);
|
470
474
|
}
|
471
475
|
} else {
|
@@ -505,18 +509,26 @@ const e = require("express");
|
|
505
509
|
links[i].toLowerCase().includes("docs.hornbill.com") ||
|
506
510
|
links[i].toLowerCase().includes("docs-internal.hornbill.com")
|
507
511
|
) {
|
508
|
-
const error_message = processErrorMessage(`Hornbill Docs links should not be fully-qualified: ${links[i]}`,
|
512
|
+
const error_message = processErrorMessage(`Hornbill Docs links should not be fully-qualified: ${links[i]}`, markdown_paths.relativePath, markdown_content, links[i]);
|
509
513
|
errors[htmlFile.relativePath].push( error_message );
|
510
514
|
continue;
|
511
515
|
}
|
512
516
|
|
513
517
|
try {
|
514
|
-
await axios
|
518
|
+
await axios({
|
519
|
+
url: links[i],
|
520
|
+
method: 'get',
|
521
|
+
timeout: 10000,
|
522
|
+
maxRedirects: 0,
|
523
|
+
validateStatus: (status) =>
|
524
|
+
status >= 200 && status < 400,
|
525
|
+
})
|
526
|
+
|
515
527
|
messages[htmlFile.relativePath].push(
|
516
528
|
`Link is a valid external URL: ${links[i]}`,
|
517
529
|
);
|
518
530
|
} catch (e) {
|
519
|
-
const error_message = processErrorMessage(`
|
531
|
+
const error_message = processErrorMessage(`Issue with external link: ${e} - ${links[i]}`, markdown_paths.relativePath, markdown_content, links[i]);
|
520
532
|
errors[htmlFile.relativePath].push(error_message);
|
521
533
|
}
|
522
534
|
}
|
@@ -524,13 +536,13 @@ const e = require("express");
|
|
524
536
|
};
|
525
537
|
|
526
538
|
const checkImages = async (source_path, htmlFile, links) => {
|
527
|
-
const
|
528
|
-
const markdown_content = fs.readFileSync(
|
539
|
+
const markdown_paths = getMDPathFromHtmlPath(htmlFile);
|
540
|
+
const markdown_content = fs.readFileSync(markdown_paths.markdownPath, 'utf8');
|
529
541
|
for (let i = 0; i < links.length; i++) {
|
530
542
|
// Validate that image is a valid URL first
|
531
543
|
if (!hdoc.valid_url(links[i])) {
|
532
544
|
// Could be a relative path, check image exists
|
533
|
-
doesFileExist(source_path, htmlFile, links[i],
|
545
|
+
doesFileExist(source_path, htmlFile, links[i], markdown_paths.relativePath, markdown_content);
|
534
546
|
} else {
|
535
547
|
messages[htmlFile.relativePath].push(
|
536
548
|
`Image link is a properly formatted external URL: ${links[i]}`,
|
@@ -543,7 +555,7 @@ const e = require("express");
|
|
543
555
|
);
|
544
556
|
} catch (e) {
|
545
557
|
// Handle errors
|
546
|
-
const error_message = processErrorMessage(`External image link error: ${links[i]} - ${e.message}`,
|
558
|
+
const error_message = processErrorMessage(`External image link error: ${links[i]} - ${e.message}`, markdown_paths.relativePath, markdown_content, links[i]);
|
547
559
|
errors[htmlFile.relativePath].push(error_message);
|
548
560
|
}
|
549
561
|
}
|
@@ -551,7 +563,7 @@ const e = require("express");
|
|
551
563
|
};
|
552
564
|
|
553
565
|
const checkTags = async (htmlFile) => {
|
554
|
-
const
|
566
|
+
const markdown_paths = getMDPathFromHtmlPath(htmlFile);
|
555
567
|
// Check if file is excluded from tag check
|
556
568
|
const file_no_ext = htmlFile.relativePath.replace(
|
557
569
|
path.extname(htmlFile.relativePath),
|
@@ -574,7 +586,7 @@ const e = require("express");
|
|
574
586
|
error_msg += h1_tags[i].text();
|
575
587
|
if (i < h1_tags.length - 1) error_msg += "; ";
|
576
588
|
}
|
577
|
-
errors[htmlFile.relativePath].push(`${
|
589
|
+
errors[htmlFile.relativePath].push(`${markdown_paths.relativePath} - ${error_msg}`);
|
578
590
|
}
|
579
591
|
};
|
580
592
|
|
@@ -600,8 +612,8 @@ const e = require("express");
|
|
600
612
|
};
|
601
613
|
|
602
614
|
const isRelativePath = (source_path, html_path, relative_path) => {
|
603
|
-
const
|
604
|
-
const markdown_content = fs.readFileSync(
|
615
|
+
const markdown_paths = getMDPathFromHtmlPath(html_path);
|
616
|
+
const markdown_content = fs.readFileSync(markdown_paths.markdownPath, 'utf8');
|
605
617
|
|
606
618
|
const rel_path_ext = path.extname(relative_path);
|
607
619
|
const response = {
|
@@ -652,7 +664,7 @@ const e = require("express");
|
|
652
664
|
}
|
653
665
|
}
|
654
666
|
if (response.has_md_extension || response.has_html_extension) {
|
655
|
-
const error_message = processErrorMessage(`Relative link has ${rel_path_ext} extension, but should not: ${relative_path}`,
|
667
|
+
const error_message = processErrorMessage(`Relative link has ${rel_path_ext} extension, but should not: ${relative_path}`, markdown_paths.relativePath, markdown_content, relative_path);
|
656
668
|
errors[html_path.relativePath].push(error_message);
|
657
669
|
return;
|
658
670
|
}
|
@@ -671,11 +683,11 @@ const e = require("express");
|
|
671
683
|
const redir = checkRedirect(source_path, relpath);
|
672
684
|
if (redir.exists) {
|
673
685
|
if (redir.error !== null) {
|
674
|
-
const error_message = processErrorMessage(`${redir.error}: ${relative_path}`,
|
686
|
+
const error_message = processErrorMessage(`${redir.error}: ${relative_path}`, markdown_paths.relativePath, markdown_content, clean_relative_path);
|
675
687
|
errors[html_path.relativePath].push(error_message);
|
676
688
|
}
|
677
689
|
} else {
|
678
|
-
const error_message = processErrorMessage(`Link path does not exist: ${relative_path}`,
|
690
|
+
const error_message = processErrorMessage(`Link path does not exist: ${relative_path}`, markdown_paths.relativePath, markdown_content, clean_relative_path);
|
679
691
|
errors[html_path.relativePath].push(error_message);
|
680
692
|
}
|
681
693
|
};
|