import{load as e}from"cheerio";const t=async(t,n)=>{let r=[],i=!1,a=!1,o=!1,s=!0,c=[];try{let l=`${t}/sitemap.xml`,u=await fetch(l,{method:`GET`,headers:{"User-Agent":`Mozilla/5.0 (compatible; SEO-Audit-Bot/1.0)`}});if(u.ok){i=!0;let t=e(await u.text(),{xmlMode:!0});if(t(`link[rel="alternate"][hreflang="x-default"], xhtml\\:link[rel="alternate"][hreflang="x-default"]`).length>0&&(a=!0),t(`link[rel="alternate"][hreflang], xhtml\\:link[rel="alternate"][hreflang]`).length>0&&(o=!0),n.size>0){let e=t(`url`),i=[],a=new Set;if(e.each((e,r)=>{let o=t(r).find(`loc`).first().text().trim();if(!o)return;let s=t(r).find(`link[rel="alternate"][hreflang], xhtml\\:link[rel="alternate"][hreflang]`),l=new Set;s.each((e,n)=>{let r=t(n).attr(`hreflang`);r&&r!==`x-default`&&(l.add(r),a.add(r))});try{let e=new URL(o).pathname.split(`/`).filter(Boolean);e.length>0&&n.has(e[0])&&(l.add(e[0]),a.add(e[0]),c.push(o))}catch{}let u=[];for(let e of n)l.has(e)||u.push(e);u.length>0&&u.length<n.size&&i.push({url:o,missingLocales:u})}),i.length>0){s=!1;for(let{url:e,missingLocales:t}of i)r.push(`URL "${e}" is missing alternate links for locales: ${t.join(`, `)}`)}let o=[];for(let e of n)a.has(e)||o.push(e);o.length>0&&(s=!1,r.push(`The following locales are completely missing from the sitemap: ${o.join(`, `)}`))}}else r.push(`sitemap.xml not found (HTTP ${u.status})`)}catch(e){r.push(`Failed to fetch sitemap.xml: ${e instanceof Error?e.message:`Unknown error`}`)}return{sitemapPresent:i,hasXDefault:a,hasAlternates:o,noLocalizedUrlsForgotten:s,localizedUrlsFound:c,errors:r}};export{t as analyzeSitemap};
//# sourceMappingURL=analyzeSitemap.mjs.map