All files / src/pages rss.xml.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28                                                       
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import type { APIContext } from "astro";
import config from "../config/index.json";
 
export async function GET(context: APIContext) {
  const posts = await getCollection("blog");
  const sorted = posts.sort(
    (a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime(),
  );
 
  return rss({
    title: config.siteTitle,
    description: config.description,
    site: context.site || config.siteUrl,
    items: sorted.slice(0, 100).map((post) => {
      const slug = post.slug;
      return {
        title: post.data.title,
        pubDate: post.data.date,
        description: post.data.description || "",
        link: `/${slug}/`,
      };
    }),
    customData: "<language>ja</language>",
  });
}