import{t as e}from"./ofetch-Dl6dVB_5.mjs";import{t}from"./cache-DUthuMSu.mjs";import{i as n}from"./common-utils-B6fqqa3X.mjs";import{Fragment as r,jsx as i,jsxs as a}from"hono/jsx/jsx-runtime";import{load as o}from"cheerio";import{renderToString as s}from"hono/jsx/dom/server";import{raw as c}from"hono/html";const l={arabic:{rootUrl:`https://www.aljazeera.net`,rssUrl:`rss`},chinese:{rootUrl:`https://chinese.aljazeera.net`,rssUrl:void 0},english:{rootUrl:`https://www.aljazeera.com`,rssUrl:`xml/rss/all.xml`}},u=(e,t)=>s(a(r,{children:[e?i(`figure`,{children:i(r,{children:c(e)})}):null,t?i(r,{children:c(t)}):null]})),d={path:`*`,name:`Unknown`,maintainers:[`nczitzk`],handler:f};async function f(r){let i=n(r)===`/`?[`arabic`]:n(r).replace(/^\//,``).split(`/`);Object.hasOwn(l,i[0])||i.unshift(`arabic`);let a=i.shift(),s=i.length===1&&i.at(-1)===`rss`&&l[a].rssUrl,c=l[a].rootUrl,d=`${c}/${s?l[a].rssUrl:i.join(`/`)}`,f=await e(d),p=o(f),m=s?f.data.match(RegExp(`<link>`+c+`/(.*?)</link>`,`g`)).map(e=>({link:e.match(/<link>(.*?)<\/link>/)[1]})):p(`.u-clickable-card__link`).toArray().map(e=>(e=p(e),{link:`${c}${e.attr(`href`)}`}));return m=await Promise.all(m.slice(0,r.req.query(`limit`)?Number.parseInt(r.req.query(`limit`)):50).map(n=>t.tryGet(n.link,async()=>{let t=await e(n.link),r=o(t);r(`.more-on`).parent().remove(),r(`.responsive-image img`).removeAttr(`srcset`);let i,a=t.match(/"datePublished": ?"(.*?)",/);if(a&&a.length>1)i=t.match(/"datePublished": ?"(.*?)",/)[1];else{let e=t.match(/"uploadDate": ?"(.*?)",/)[1];i=e&&e.length>1?e:r(`div.date-simple > span:nth-child(2)`).text()}return n.title=r(`h1`).first().text(),n.author=r(`.author`).text(),n.pubDate=i,n.description=u(r(`.article-featured-image`).html(),r(`.wysiwyg`).html()),n}))),{title:p(`title`).first().text(),link:d,item:m}}export{d as route};