Multiple feeds and improve rendering
This commit is contained in:
parent
dadbd32e1b
commit
d56a8cc95d
13 changed files with 273 additions and 184 deletions
23
src/pages/blog/feed.xml.ts
Normal file
23
src/pages/blog/feed.xml.ts
Normal 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)),
|
||||
),
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue