@uxf/scripts 11.61.3 → 11.61.5
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/package.json +1 -1
- package/src/uxf-sitemap-check/index.js +40 -15
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ const URLS_LABEL = "🔗 Links:";
|
|
|
17
17
|
|
|
18
18
|
const TESTED_URLS = [];
|
|
19
19
|
const URLS_TO_CHECK = new Set();
|
|
20
|
+
const ERRORS = [];
|
|
20
21
|
|
|
21
22
|
const robotsParser = robotsTxtParser({ userAgent: "uxf-bot", allowOnNeutral: false });
|
|
22
23
|
|
|
@@ -73,6 +74,7 @@ function createErrorList(errors) {
|
|
|
73
74
|
function createErrorResult(errors) {
|
|
74
75
|
let parentPages = "";
|
|
75
76
|
let nestedPages = "";
|
|
77
|
+
let generalErrors = "";
|
|
76
78
|
|
|
77
79
|
const parentPagesErrors = errors.filter((url) => url.parentUrl === undefined);
|
|
78
80
|
if (parentPagesErrors.length > 0) {
|
|
@@ -103,7 +105,14 @@ function createErrorResult(errors) {
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
if (ERRORS.length > 0) {
|
|
109
|
+
generalErrors = `\n\nGeneral errors:\n`;
|
|
110
|
+
for (const error of ERRORS) {
|
|
111
|
+
generalErrors += `${createTabSpace(1)}${error}\n`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return parentPages + nestedPages + generalErrors;
|
|
107
116
|
}
|
|
108
117
|
|
|
109
118
|
/**
|
|
@@ -251,7 +260,15 @@ async function testUrl(url, webUrl, parentUrl = undefined) {
|
|
|
251
260
|
const indexInChecked = TESTED_URLS.findIndex((result) => result.url === url);
|
|
252
261
|
if (indexInChecked === -1) {
|
|
253
262
|
const result = await fetchUrl(url, webUrl, parentUrl);
|
|
254
|
-
TESTED_URLS.push(
|
|
263
|
+
TESTED_URLS.push({
|
|
264
|
+
isImg: result.isImg,
|
|
265
|
+
message: result.message,
|
|
266
|
+
parentUrl: result.parentUrl,
|
|
267
|
+
skipped: result.skipped,
|
|
268
|
+
status: result.status,
|
|
269
|
+
ttl: result.ttl,
|
|
270
|
+
url: result.url,
|
|
271
|
+
});
|
|
255
272
|
return result;
|
|
256
273
|
}
|
|
257
274
|
return TESTED_URLS[indexInChecked];
|
|
@@ -296,13 +313,17 @@ async function testSitemapUrls(urls, webUrl, sitemapUrl, skip, withNested, withI
|
|
|
296
313
|
* @return {Promise<void>}
|
|
297
314
|
*/
|
|
298
315
|
async function testNestedUrls(html, parentUrl, parentIndex, webUrl) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
316
|
+
try {
|
|
317
|
+
const $ = cheerio.load(html);
|
|
318
|
+
const urls = createCorrectLinks(
|
|
319
|
+
$("a[href]").map((i, node) => $(node).attr("href")),
|
|
320
|
+
webUrl,
|
|
321
|
+
);
|
|
304
322
|
|
|
305
|
-
|
|
323
|
+
await testNested(urls, parentIndex, parentUrl, createTabSpace() + URLS_LABEL, webUrl);
|
|
324
|
+
} catch (e) {
|
|
325
|
+
ERRORS.push(`Can't test all nested pages for ${parentUrl} - ${e.message}`);
|
|
326
|
+
}
|
|
306
327
|
}
|
|
307
328
|
|
|
308
329
|
/**
|
|
@@ -313,13 +334,17 @@ async function testNestedUrls(html, parentUrl, parentIndex, webUrl) {
|
|
|
313
334
|
* @return {Promise<void>}
|
|
314
335
|
*/
|
|
315
336
|
async function testNestedImages(html, parentUrl, parentIndex, webUrl) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
337
|
+
try {
|
|
338
|
+
const $ = cheerio.load(html);
|
|
339
|
+
const images = createCorrectLinks(
|
|
340
|
+
$("img[src]").map((i, node) => $(node).attr("src")),
|
|
341
|
+
webUrl,
|
|
342
|
+
);
|
|
321
343
|
|
|
322
|
-
|
|
344
|
+
await testNested(images, parentIndex, parentUrl, createTabSpace() + IMAGES_LABEL, webUrl);
|
|
345
|
+
} catch (e) {
|
|
346
|
+
ERRORS.push(`Can't test all nested images for ${parentUrl} - ${e.message}`);
|
|
347
|
+
}
|
|
323
348
|
}
|
|
324
349
|
|
|
325
350
|
/**
|
|
@@ -452,7 +477,7 @@ module.exports = async function run(sitemapUrl, skip, withNested, withImages, go
|
|
|
452
477
|
const skippedUrls = TESTED_URLS.filter((r) => r.status !== 200 && r.skipped === true);
|
|
453
478
|
const ok = TESTED_URLS.filter((r) => r.status === 200);
|
|
454
479
|
|
|
455
|
-
if (errors.length > 0) {
|
|
480
|
+
if (errors.length > 0 || ERRORS.length > 0) {
|
|
456
481
|
const errorText = createErrorResult(errors);
|
|
457
482
|
logErrors(errorText, "\n\n\nErrors:\n");
|
|
458
483
|
await sendGoogleChatMessage(errorText, googleWebhookUrl);
|