A fullstack app for indexing standard.site documents
1import { Hono } from "hono";
2import { Feed } from "feed";
3import type { Bindings, ResolvedDocumentRow } from "../types";
4
5const rss = new Hono<{ Bindings: Bindings }>();
6
7rss.get("/", async (c) => {
8 try {
9 const db = c.env.DB;
10
11 const { results } = await db
12 .prepare(
13 `SELECT uri, did, rkey, title, description, path, site, content, text_content,
14 cover_image_cid, cover_image_url, bsky_post_ref, tags,
15 published_at, updated_at, pub_url, pub_name, pub_description,
16 pub_icon_cid, pub_icon_url, view_url, pds_endpoint,
17 resolved_at, stale_at, verified
18 FROM resolved_documents
19 WHERE verified = 1
20 ORDER BY published_at DESC
21 LIMIT 50`,
22 )
23 .all<ResolvedDocumentRow>();
24
25 const feed = new Feed({
26 title: "Docs.surf",
27 description: "A feed of standard.site documents to surf",
28 id: "https://docs.surf/",
29 link: "https://docs.surf/",
30 copyright: "",
31 });
32
33 for (const row of results || []) {
34 feed.addItem({
35 title: row.title || "Untitled",
36 id: row.uri,
37 link: row.view_url || row.uri,
38 description: row.description || undefined,
39 date: row.published_at ? new Date(row.published_at) : new Date(),
40 });
41 }
42
43 return c.body(feed.rss2(), 200, {
44 "Content-Type": "application/xml",
45 });
46 } catch (error) {
47 return c.json(
48 { error: "Failed to generate RSS feed", details: String(error) },
49 500,
50 );
51 }
52});
53
54export default rss;