aeorank 2.3.1 → 2.3.2

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/dist/index.js CHANGED
@@ -185,16 +185,20 @@ async function prefetchSiteData(domain) {
185
185
  }
186
186
  }
187
187
  }
188
- let blogSample = [];
189
- if (sitemapXml && sitemapXml.status === 200) {
190
- let sitemapForBlog = sitemapXml.text;
191
- const subSitemapUrl = extractSubSitemapUrl(sitemapForBlog);
192
- if (subSitemapUrl) {
193
- const subSitemap = await fetchText(subSitemapUrl);
194
- if (subSitemap && subSitemap.status === 200) {
195
- sitemapForBlog = subSitemap.text;
188
+ if (sitemapXml && sitemapXml.status === 200 && sitemapXml.text.includes("<sitemapindex")) {
189
+ const subUrls = extractAllSubSitemapUrls(sitemapXml.text, 5);
190
+ if (subUrls.length > 0) {
191
+ const subResults = await Promise.all(subUrls.map((u) => fetchText(u)));
192
+ for (const sub of subResults) {
193
+ if (sub && sub.status === 200) {
194
+ sitemapXml.text += "\n" + sub.text;
195
+ }
196
196
  }
197
197
  }
198
+ }
199
+ let blogSample = [];
200
+ if (sitemapXml && sitemapXml.status === 200) {
201
+ const sitemapForBlog = sitemapXml.text;
198
202
  const blogUrls = extractBlogUrlsFromSitemap(sitemapForBlog, domain, 50);
199
203
  if (blogUrls.length > 0) {
200
204
  const fetched = await Promise.all(blogUrls.map((url) => fetchText(url)));
@@ -1239,16 +1243,16 @@ function extractBlogUrlsFromSitemap(sitemapText, domain, limit = 50) {
1239
1243
  });
1240
1244
  return candidates.slice(0, limit).map((c) => c.url);
1241
1245
  }
1242
- function extractSubSitemapUrl(sitemapText) {
1243
- if (!sitemapText.includes("<sitemapindex")) return null;
1246
+ function extractAllSubSitemapUrls(sitemapText, limit = 5) {
1247
+ if (!sitemapText.includes("<sitemapindex")) return [];
1244
1248
  const sitemapLocs = sitemapText.match(/<sitemap>[\s\S]*?<loc>([^<]+)<\/loc>[\s\S]*?<\/sitemap>/gi) || [];
1245
- if (sitemapLocs.length === 0) return null;
1246
1249
  const urls = sitemapLocs.map((block) => {
1247
1250
  const match = block.match(/<loc>([^<]+)<\/loc>/i);
1248
1251
  return match ? match[1].trim() : "";
1249
1252
  }).filter(Boolean);
1250
- const preferred = urls.find((u) => /post|blog|article/i.test(u));
1251
- return preferred || urls[0] || null;
1253
+ const preferred = urls.filter((u) => /post|blog|article|page/i.test(u));
1254
+ const rest = urls.filter((u) => !preferred.includes(u));
1255
+ return [...preferred, ...rest].slice(0, limit);
1252
1256
  }
1253
1257
  function checkContentVelocity(data) {
1254
1258
  const findings = [];