Skip to content

Commit b58991f

Browse files
authored
Merge pull request #166 from fulldecent/copilot/fix-99a38ce5-7421-4680-9b8b-bb5c47f9070f
Make proxy URL optional configurable option in external-links HTML validation rule
2 parents 38d222c + d63a478 commit b58991f

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

.htmlvalidate.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ export default defineConfig({
1919
},
2020
],
2121
"pacific-medical-training/mailto-awesome": "error",
22-
"pacific-medical-training/external-links": "error",
22+
"pacific-medical-training/external-links": [
23+
"error",
24+
{
25+
proxyUrl: "https://api.PacificMedicalTraining.com/public/link-check/status",
26+
},
27+
],
2328
"pacific-medical-training/no-jquery": "error",
2429
"pacific-medical-training/canonical-link": "error",
2530
"pacific-medical-training/latest-packages": "error",

test/plugin.html-validate.external-links.mjs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ const TIMEOUT_SECONDS = 5;
1212
const USER_AGENT =
1313
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.9999.999 Safari/537.36";
1414

15-
// Use your proxy server to check external links
16-
// This URL must accept a query parameter `url` and return the status code and possibly location: header in the response.
17-
// Status code 500 is returned if the server is down or timeout.
18-
const PROXY_URL = "https://api.PacificMedicalTraining.com/public/link-check/status";
19-
2015
// html-validate runs check() synchronously, so we can't use async functions like fetch here. Maybe after their
2116
// version 9 release we can use the fetch API and this parallel approach.
2217
/**
@@ -61,6 +56,21 @@ function normalizeUrl(url) {
6156
}
6257

6358
export default class ExternalLinksRule extends Rule {
59+
constructor(options) {
60+
super(options);
61+
this.proxyUrl = options?.proxyUrl;
62+
}
63+
64+
static schema() {
65+
return {
66+
proxyUrl: {
67+
type: "string",
68+
description:
69+
"URL of proxy server to check external links. Must accept a query parameter 'url' and return the status code and possibly location: header in the response.",
70+
},
71+
};
72+
}
73+
6474
documentation() {
6575
return {
6676
description: "Require all external links to be live.",
@@ -142,7 +152,7 @@ export default class ExternalLinksRule extends Rule {
142152
// Normalize URL to handle case-insensitive domains
143153
const normalizedUrl = normalizeUrl(url);
144154

145-
const urlWithQuery = `${PROXY_URL}?url=${encodeURIComponent(url)}`;
155+
const urlWithQuery = `${this.proxyUrl}?url=${encodeURIComponent(url)}`;
146156
// Use shell-quote to safely escape the URL
147157
const escapedUrl = shellEscape([urlWithQuery]);
148158

@@ -218,7 +228,7 @@ export default class ExternalLinksRule extends Rule {
218228
}
219229
}
220230

221-
if (PROXY_URL !== null) {
231+
if (this.proxyUrl) {
222232
this.checkWithProxy(url, target);
223233
} else {
224234
this.check(url, target);

0 commit comments

Comments
 (0)