Back

Version 130

6/26/2023
const rssViewer = @easrng.preactWebApp(
async function App(
{ html, req, setHeaders }: typeof $easrng.preactWebApp.props,
) {
const { default: TimeAgo } = await import("npm:javascript-time-ago");
const { default: en } = await import("npm:javascript-time-ago/locale/en");
TimeAgo.addDefaultLocale(en);
const timeAgo = new TimeAgo("en-US");
const extractor = await import(
"https://esm.sh/@extractus/feed-extractor@6.2.3/src/main.js"
);
const extract = async (url, options = {}, fetchOptions = {}) => {
const retrieve_default = async (url, options: any = {}) => {
const {
headers = {
"user-agent":
"Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0",
},
} = options;
const res = await fetch(url, { headers, redirect: "follow" });
const status = res.status;
if (status >= 400) {
throw new Error(`Request failed with error code ${status}`);
}
const contentType = res.headers.get("content-type");
const text = await res.text();
if (/(\+|\/)(xml|html)/.test(contentType)) {
return { type: "xml", text: text.trim(), status, contentType };
}
if (/(\+|\/)json/.test(contentType)) {
try {
const data = JSON.parse(text);
return { type: "json", json: data, status, contentType };
}
catch (err) {
throw new Error("Failed to convert data to JSON object");
easrng-rssviewer.web.val.run
Updated: September 13, 2024