@uxf/scripts 11.61.4 → 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 +31 -14
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
|
/**
|
|
@@ -304,13 +313,17 @@ async function testSitemapUrls(urls, webUrl, sitemapUrl, skip, withNested, withI
|
|
|
304
313
|
* @return {Promise<void>}
|
|
305
314
|
*/
|
|
306
315
|
async function testNestedUrls(html, parentUrl, parentIndex, webUrl) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
316
|
+
try {
|
|
317
|
+
const $ = cheerio.load(html);
|
|
318
|
+
const urls = createCorrectLinks(
|
|
319
|
+
$("a[href]").map((i, node) => $(node).attr("href")),
|
|
320
|
+
webUrl,
|
|
321
|
+
);
|
|
312
322
|
|
|
313
|
-
|
|
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
|
+
}
|
|
314
327
|
}
|
|
315
328
|
|
|
316
329
|
/**
|
|
@@ -321,13 +334,17 @@ async function testNestedUrls(html, parentUrl, parentIndex, webUrl) {
|
|
|
321
334
|
* @return {Promise<void>}
|
|
322
335
|
*/
|
|
323
336
|
async function testNestedImages(html, parentUrl, parentIndex, webUrl) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
337
|
+
try {
|
|
338
|
+
const $ = cheerio.load(html);
|
|
339
|
+
const images = createCorrectLinks(
|
|
340
|
+
$("img[src]").map((i, node) => $(node).attr("src")),
|
|
341
|
+
webUrl,
|
|
342
|
+
);
|
|
329
343
|
|
|
330
|
-
|
|
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
|
+
}
|
|
331
348
|
}
|
|
332
349
|
|
|
333
350
|
/**
|
|
@@ -460,7 +477,7 @@ module.exports = async function run(sitemapUrl, skip, withNested, withImages, go
|
|
|
460
477
|
const skippedUrls = TESTED_URLS.filter((r) => r.status !== 200 && r.skipped === true);
|
|
461
478
|
const ok = TESTED_URLS.filter((r) => r.status === 200);
|
|
462
479
|
|
|
463
|
-
if (errors.length > 0) {
|
|
480
|
+
if (errors.length > 0 || ERRORS.length > 0) {
|
|
464
481
|
const errorText = createErrorResult(errors);
|
|
465
482
|
logErrors(errorText, "\n\n\nErrors:\n");
|
|
466
483
|
await sendGoogleChatMessage(errorText, googleWebhookUrl);
|