import { Readability } from "npm:@mozilla/readability";
import { JSDOM } from "npm:jsdom";
export default async function(req: Request) {
let resp = await fetch(`https://${new URL(req.url).pathname}`, req);
let body = await resp.text();
let doc = new JSDOM(body);
let reader = new Readability(doc.window.document.cloneNode(true));
let article = reader.parse();
console.log(article.content);
return new Response(
`
<html>
<head>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
/>
</head>
<body>
<main>
${article.content}
</main>
</body>
</html>
`,
{
headers: {
"Content-Type": "text/html",
},
},
);
}