@uxf/scripts 1.5.5 → 1.6.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/.gitlab-ci.yml +1 -1
- package/package.json +1 -1
- package/src/uxf-sitemap-check/index.js +50 -8
package/.gitlab-ci.yml
CHANGED
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ const GoogleChat = require("../GoogleChat");
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
|
-
* @typedef {{parentUrl: (string | undefined), isImg: boolean, time: number, ttl: number, url: string, status: number, message: (string | undefined)}} UrlCheckResponse
|
|
11
|
+
* @typedef {{parentUrl: (string | undefined), isImg: boolean, time: number, ttl: number, url: string, status: number, message: (string | undefined), shouldIgnoreError: (boolean | undefined)}} UrlCheckResponse
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
const MAX_TTL = 3;
|
|
@@ -34,6 +34,24 @@ function isImageUrl(url) {
|
|
|
34
34
|
return new RegExp("[a-z].*(\\.jpg|\\.png|\\.webp|\\.avif|\\.gif)$", "gim").test(url);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param url {string}
|
|
40
|
+
* @param status {number}
|
|
41
|
+
* @param e {Error}
|
|
42
|
+
* @returns {boolean}
|
|
43
|
+
*/
|
|
44
|
+
function shouldIgnoreError(url, status, e) {
|
|
45
|
+
if (status === 999 && url.startsWith("https://www.linkedin.com")) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if ((status === -1 || status === 302) && url.startsWith("https://www.facebook.com/sharer/")) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
37
55
|
/**
|
|
38
56
|
*
|
|
39
57
|
* @param errors {UrlCheckResponse[]}
|
|
@@ -128,14 +146,28 @@ async function fetchUrl(url, parentUrl = undefined, ttl = 1) {
|
|
|
128
146
|
time: Math.ceil(t1 - t0),
|
|
129
147
|
};
|
|
130
148
|
} catch (e) {
|
|
149
|
+
const status = Number.parseInt((e && e.response && e.response.status) || -1, 10);
|
|
150
|
+
|
|
151
|
+
if (shouldIgnoreError(url, status, e)) {
|
|
152
|
+
return {
|
|
153
|
+
url,
|
|
154
|
+
parentUrl,
|
|
155
|
+
isImg: isImageUrl(url),
|
|
156
|
+
ttl,
|
|
157
|
+
status,
|
|
158
|
+
shouldIgnoreError: true,
|
|
159
|
+
time: 0,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
131
162
|
return {
|
|
132
163
|
url,
|
|
133
164
|
parentUrl,
|
|
134
165
|
isImg: isImageUrl(url),
|
|
135
166
|
ttl,
|
|
136
|
-
status
|
|
167
|
+
status,
|
|
137
168
|
time: 0,
|
|
138
169
|
message: e.message,
|
|
170
|
+
shouldIgnoreError: false,
|
|
139
171
|
};
|
|
140
172
|
}
|
|
141
173
|
}
|
|
@@ -251,9 +283,10 @@ function printUrlResult(result) {
|
|
|
251
283
|
/**
|
|
252
284
|
*
|
|
253
285
|
* @param errorText {string}
|
|
286
|
+
* @param title {string}
|
|
254
287
|
*/
|
|
255
|
-
function logErrors(errorText) {
|
|
256
|
-
stdout.write(
|
|
288
|
+
function logErrors(errorText, title) {
|
|
289
|
+
stdout.write(title);
|
|
257
290
|
stdout.write(`${errorText}\n\n`);
|
|
258
291
|
}
|
|
259
292
|
|
|
@@ -275,8 +308,8 @@ function convertTime(millis) {
|
|
|
275
308
|
*/
|
|
276
309
|
function logStatistics(okResults, time) {
|
|
277
310
|
const avgTime = Math.round(okResults.reduce((prev, curr) => prev + curr.time, 0) / TESTED_URLS.length);
|
|
278
|
-
const maxTime = okResults.reduce((prev, curr) => (curr.time > prev.time ? curr : prev));
|
|
279
|
-
const minTime = okResults.reduce((prev, curr) => (curr.time < prev.time ? curr : prev));
|
|
311
|
+
const maxTime = okResults.reduce((prev, curr) => (curr.time > prev.time ? curr : prev), []);
|
|
312
|
+
const minTime = okResults.reduce((prev, curr) => (curr.time < prev.time ? curr : prev), []);
|
|
280
313
|
|
|
281
314
|
stdout.write("\nSummary:\n");
|
|
282
315
|
stdout.write(createTabSpace() + `Time ${convertTime(time)}\n`);
|
|
@@ -350,15 +383,24 @@ module.exports = async function run(sitemapUrl, webUrl, slackChannel, skip, test
|
|
|
350
383
|
await testSitemapUrls((await Sitemap.getSitemap(sitemapUrl)), webUrl, sitemapUrl, skip, testNested);
|
|
351
384
|
const finishTime = performance.now();
|
|
352
385
|
|
|
353
|
-
const errors = TESTED_URLS.filter(r => r.status !== 200);
|
|
386
|
+
const errors = TESTED_URLS.filter(r => r.status !== 200 && r.shouldIgnoreError === false);
|
|
387
|
+
const ignoredErrors = TESTED_URLS.filter(r => r.status !== 200 && r.shouldIgnoreError === true);
|
|
354
388
|
const ok = TESTED_URLS.filter(r => r.status === 200);
|
|
355
389
|
|
|
356
390
|
if (errors.length > 0) {
|
|
357
391
|
const errorText = createErrorResult(errors);
|
|
358
|
-
logErrors(errorText);
|
|
392
|
+
logErrors(errorText, "\nErrors:\n");
|
|
393
|
+
const ignoredErrorText = createErrorResult(ignoredErrors);
|
|
394
|
+
logErrors(ignoredErrorText, "\nIngored errors:\n");
|
|
359
395
|
await sendSlackMessage(errorText, slackChannel);
|
|
360
396
|
await sendGoogleChatMessage(errors);
|
|
361
397
|
}
|
|
398
|
+
|
|
399
|
+
if (ignoredErrors.length > 0) {
|
|
400
|
+
const ignoredErrorText = createErrorResult(ignoredErrors);
|
|
401
|
+
logErrors(ignoredErrorText, "\nIngored errors:\n");
|
|
402
|
+
}
|
|
403
|
+
|
|
362
404
|
logStatistics(ok, Math.ceil(finishTime - startTime));
|
|
363
405
|
|
|
364
406
|
process.exit(errors.length > 0 ? 1 : 0);
|