SPB Git

spb/autoscholar

Public
1.5 KB · 27 lines typescript
1import { allPublishedForFeeds } from "@autoscholar/core";2import { db } from "@/lib/server/db";34export const runtime = "nodejs";5export const dynamic = "force-dynamic";6const esc = (s: string) =>7  s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");89export async function GET() {10  const base = process.env.APP_BASE_URL ?? "http://localhost:8470";11  const rows = await allPublishedForFeeds(db(), 100);12  const updated = rows[0] ? new Date(rows[0].p.updatedAt).toISOString() : new Date().toISOString();13  const entries = rows14    .map(15      (r) =>16        `<entry><title>${esc(r.v.title)}</title><link href="${base}/research/${r.p.slug}"/><id>${base}/research/${r.p.slug}</id><updated>${new Date(r.p.updatedAt).toISOString()}</updated><published>${new Date(r.v.publishedAt).toISOString()}</published><author><name>AutoScholar (AI-generated research)</name></author><summary>${esc(r.v.abstract)}</summary>${r.v.keywords.map((k) => `<category term="${esc(k)}"/>`).join("")}</entry>`,17    )18    .join("");19  const xml = `<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title>AutoScholar.ai working papers</title><link href="${base}/research"/><link rel="self" href="${base}/feed.atom"/><id>${base}/</id><updated>${updated}</updated>${entries}</feed>`;20  return new Response(xml, {21    headers: {22      "content-type": "application/atom+xml; charset=utf-8",23      "cache-control": "public, max-age=300",24    },25  });26}27
Files · main
Menu

Theme