Improve feeds according to W3C

This commit is contained in:
Bad Manners 2024-09-15 16:54:28 -03:00
parent d56a8cc95d
commit c1a59ed51a
No known key found for this signature in database
GPG key ID: 8C88292CCB075609
9 changed files with 137 additions and 53 deletions

View file

@ -6,6 +6,9 @@ import { blogFeedItem, type EntryWithPubDate } from "@utils/feed";
const MAX_ITEMS = 8;
export const GET: APIRoute = async ({ site }) => {
if (!site) {
throw new Error("site is required.");
}
const posts = (
(await getCollection("blog", (post) => !post.data.isDraft && post.data.pubDate)) as EntryWithPubDate<"blog">[]
)
@ -15,7 +18,9 @@ export const GET: APIRoute = async ({ site }) => {
return rss({
title: "Blog | Bad Manners",
description: "Blog posts by Bad Manners.",
site: new URL("/blog", site!),
site: new URL("blog", site),
xmlns: { atom: "http://www.w3.org/2005/Atom" },
customData: `<link href="${new URL("blog", site)}" rel="alternate" type="text/html" /><atom:link href="${new URL("blog/feed.xml", site)}" rel="self" type="application/rss+xml" />`,
items: await Promise.all(
posts.map(async ({ data, slug, render }) => blogFeedItem(site, data, slug, (await render()).Content)),
),