import{t as e}from"./parse-date-BdYTmLpo.mjs";import{i as t}from"./common-utils-B6fqqa3X.mjs";import{t as n}from"./got-BBDj7u1e.mjs";import{jsx as r}from"hono/jsx/jsx-runtime";import{load as i}from"cheerio";import{renderToString as a}from"hono/jsx/dom/server";const o={path:`*`,name:`Unknown`,maintainers:[],handler:s};async function s(o){let s=o.req.query(`limit`)?Number.parseInt(o.req.query(`limit`),10):50,c=`https://aqara.com`,l=`wp-json/wp/v2`,u,d=c,f=new URL(`${l}/posts?_embed=true&per_page=${s}`,c).href,p=t(o).match(/^\/([^/]*)\/([^/]*)\/(.*)$/);if(p){let e=p[1],t=p[2]===`tag`?`tags`:p[2]===`category`?`categories`:p[2],r=decodeURI(p[3].split(`/`).pop()),i=new URL(`${e}/${l}/${t}?search=${r}`,c).href,{data:a}=await n(i),o=a.pop();(o?.id??void 0)&&(u=o.name??r,d=o.link??d,f=new URL(`${e}/${l}/posts?_embed=true&per_page=${s}&${t}=${o.id}`,c).href)}let{data:m}=await n(f),h=m.slice(0,s).map(t=>{let n=t._embedded[`wp:term`],o=i(t.content?.rendered??t.content);return o(`figure`).each(function(){let e=o(this).find(`img`),t=(e.prop(`data-actualsrc`)??e.prop(`data-original`)??e.prop(`src`)).replace(/(-\d+x\d+)/,``),n=e.prop(`data-rawwidth`)??e.prop(`width`),i=e.prop(`data-rawheight`)??e.prop(`height`);o(this).replaceWith(a(r(`figure`,{children:r(`img`,{src:t,width:n,height:i})})))}),{title:t.title?.rendered??t.title,link:t.link,description:o.html(),author:t._embedded.author.map(e=>e.name).join(`/`),category:n.flat().map(e=>e.name),guid:t.guid?.rendered??t.guid,pubDate:e(t.date_gmt),updated:e(t.modified_gmt)}}),{data:g}=await n(d),_=i(g),v=_(`link[rel="apple-touch-icon"]`).first().prop(`href`),y=_(`meta[property="og:site_name"]`).prop(`content`)??`Aqara`;return{item:h,title:`${y}${u?` - ${u}`:``}`,link:d,description:_(`meta[property="og:title"]`).prop(`content`),language:_(`meta[property="og:locale"]`).prop(`content`),image:_(`meta[name="msapplication-TileImage"]`).prop(`content`),icon:v,logo:v,subtitle:_(`meta[property="og:type"]`).prop(`content`),author:y}}export{o as route};