Multiple feeds and improve rendering

This commit is contained in:
Bad Manners 2024-09-14 21:55:46 -03:00
parent dadbd32e1b
commit d56a8cc95d
No known key found for this signature in database
GPG key ID: 8C88292CCB075609
13 changed files with 273 additions and 184 deletions

View file

@ -0,0 +1,23 @@
import rss from "@astrojs/rss";
import type { APIRoute } from "astro";
import { getCollection } from "astro:content";
import { blogFeedItem, type EntryWithPubDate } from "@utils/feed";
const MAX_ITEMS = 8;
export const GET: APIRoute = async ({ site }) => {
const posts = (
(await getCollection("blog", (post) => !post.data.isDraft && post.data.pubDate)) as EntryWithPubDate<"blog">[]
)
.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime())
.slice(0, MAX_ITEMS);
return rss({
title: "Blog | Bad Manners",
description: "Blog posts by Bad Manners.",
site: new URL("/blog", site!),
items: await Promise.all(
posts.map(async ({ data, slug, render }) => blogFeedItem(site, data, slug, (await render()).Content)),
),
});
};