import{t as rofetch}from"./ofetch-Dl6dVB_5.mjs";import{t as parseDate}from"./parse-date-BdYTmLpo.mjs";import{t as timezone}from"./timezone-keeL11Io.mjs";import{load}from"cheerio";import iconv from"iconv-lite";function transElemText($,prop){const regex=/\$\((.*)\)/g;let result=prop;const parseDate$1=parseDate,timezone$1=timezone;return regex.test(result)&&(result=eval(result)),result}function replaceParams(e,t,n){let r=/%(.*)%/g,i=t,a=r.exec(t);for(;a;)i=i.replace(a[0],transElemText(n,e.params[a[1]])),a=r.exec(t);return i}function getProp(e,t,n){let r=e;if(Array.isArray(t))for(let e of t)r=transElemText(n,r[e]);else r=transElemText(n,r[t]);return replaceParams(e,r,n)}async function buildData(e){let t=await rofetch.raw(e.url),n=t.headers.get(`content-type`)||``,r=`utf-8`;for(let e of n.split(`;`))e.includes(`charset=`)&&(r=(e.split(`=`).pop()||`utf-8`).toLowerCase());let i=load(r===`utf-8`?t._data:iconv.decode(await rofetch(e.url,{responseType:`buffer`}),r)),a=i(e.item.item);return{link:e.link,title:getProp(e,`title`,i),description:getProp(e,`description`,i),allowEmpty:e.allowEmpty||!1,item:a.toArray().map(t=>{let n=e=>i(t).find(e);return{title:getProp(e,[`item`,`title`],n),description:getProp(e,[`item`,`description`],n),pubDate:getProp(e,[`item`,`pubDate`],n),link:getProp(e,[`item`,`link`],n),guid:getProp(e,[`item`,`guid`],n)}})}}export{buildData as t};