Leaflet Blog in Deno Fresh
at main 1.5 kB view raw
1import rehypeFormat from "npm:rehype-format"; 2import rehypeStringify from "npm:rehype-stringify"; 3import remarkParse from "npm:remark-parse"; 4import remarkRehype from "npm:remark-rehype"; 5import RSS from "npm:rss"; 6import { unified } from "npm:unified"; 7 8import { getPosts } from "../lib/api.ts"; 9 10export const dynamic = "force-static"; 11export const revalidate = 3600; // 1 hour 12 13export async function GET() { 14 const posts = await getPosts(); 15 16 const rss = new RSS({ 17 title: "knotbin", 18 feed_url: "https://knotbin.com/rss", 19 site_url: "https://knotbin.com", 20 description: "a webbed site", 21 }); 22 23 for (const post of posts) { 24 const description = post.value.subtitle 25 ? `${post.value.subtitle}\n\n${await unified() 26 .use(remarkParse) 27 .use(remarkRehype) 28 .use(rehypeFormat) 29 .use(rehypeStringify) 30 .process(post.value.content) 31 .then((v) => v.toString())}` 32 : await unified() 33 .use(remarkParse) 34 .use(remarkRehype) 35 .use(rehypeFormat) 36 .use(rehypeStringify) 37 .process(post.value.content) 38 .then((v) => v.toString()); 39 40 rss.item({ 41 title: post.value.title ?? "Untitled", 42 description, 43 url: `https://knotbin.com/post/${post.uri.split("/").pop()}`, 44 date: new Date(post.value.createdAt ?? Date.now()), 45 }); 46 } 47 48 return new Response(rss.xml(), { 49 headers: { 50 "content-type": "application/rss+xml", 51 }, 52 }); 53} 54 55export const handler = { 56 GET, 57 dynamic, 58 revalidate, 59};