export default { async fetch(request) { const rssUrl = "https://simplify8.weebly.com/slot/1/feed.xml"; const response = await fetch(rssUrl); const xml = await response.text(); const items = [...xml.matchAll(/([\s\S]*?)<\/item>/g)]; let posts = items.slice(0,5).map(item => { let content = item[1]; let title = content.match(/(.*?)<\/title>/)?.[1] || ""; let link = content.match(/<link>(.*?)<\/link>/)?.[1] || ""; let pubDate = content.match(/<pubDate>(.*?)<\/pubDate>/)?.[1] || ""; let desc = content.match(/<description>([\s\S]*?)<\/description>/)?.[1] || ""; let imgMatch = desc.match(/<img.*?src="(.*?)"/); let image = imgMatch ? imgMatch[1] : ""; return { title, link, pubDate, image }; }); return new Response(JSON.stringify(posts), { headers: { "content-type": "application/json", "Access-Control-Allow-Origin": "*" } }); } }