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.cjs CHANGED
@@ -544,16 +544,20 @@ async function prefetchSiteData(domain) {
544
544
  }
545
545
  }
546
546
  }
547
- let blogSample = [];
548
- if (sitemapXml && sitemapXml.status === 200) {
549
- let sitemapForBlog = sitemapXml.text;
550
- const subSitemapUrl = extractSubSitemapUrl(sitemapForBlog);
551
- if (subSitemapUrl) {
552
- const subSitemap = await fetchText(subSitemapUrl);
553
- if (subSitemap && subSitemap.status === 200) {
554
- sitemapForBlog = subSitemap.text;
547
+ if (sitemapXml && sitemapXml.status === 200 && sitemapXml.text.includes("<sitemapindex")) {
548
+ const subUrls = extractAllSubSitemapUrls(sitemapXml.text, 5);
549
+ if (subUrls.length > 0) {
550
+ const subResults = await Promise.all(subUrls.map((u) => fetchText(u)));
551
+ for (const sub of subResults) {
552
+ if (sub && sub.status === 200) {
553
+ sitemapXml.text += "\n" + sub.text;
554
+ }
555
555
  }
556
556
  }
557
+ }
558
+ let blogSample = [];
559
+ if (sitemapXml && sitemapXml.status === 200) {
560
+ const sitemapForBlog = sitemapXml.text;
557
561
  const blogUrls = extractBlogUrlsFromSitemap(sitemapForBlog, domain, 50);
558
562
  if (blogUrls.length > 0) {
559
563
  const fetched = await Promise.all(blogUrls.map((url) => fetchText(url)));
@@ -1598,16 +1602,16 @@ function extractBlogUrlsFromSitemap(sitemapText, domain, limit = 50) {
1598
1602
  });
1599
1603
  return candidates.slice(0, limit).map((c) => c.url);
1600
1604
  }
1601
- function extractSubSitemapUrl(sitemapText) {
1602
- if (!sitemapText.includes("<sitemapindex")) return null;
1605
+ function extractAllSubSitemapUrls(sitemapText, limit = 5) {
1606
+ if (!sitemapText.includes("<sitemapindex")) return [];
1603
1607
  const sitemapLocs = sitemapText.match(/<sitemap>[\s\S]*?<loc>([^<]+)<\/loc>[\s\S]*?<\/sitemap>/gi) || [];
1604
- if (sitemapLocs.length === 0) return null;
1605
1608
  const urls = sitemapLocs.map((block) => {
1606
1609
  const match = block.match(/<loc>([^<]+)<\/loc>/i);
1607
1610
  return match ? match[1].trim() : "";
1608
1611
  }).filter(Boolean);
1609
- const preferred = urls.find((u) => /post|blog|article/i.test(u));
1610
- return preferred || urls[0] || null;
1612
+ const preferred = urls.filter((u) => /post|blog|article|page/i.test(u));
1613
+ const rest = urls.filter((u) => !preferred.includes(u));
1614
+ return [...preferred, ...rest].slice(0, limit);
1611
1615
  }
1612
1616
  function checkContentVelocity(data) {
1613
1617
  const findings = [];