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)),
),

View file

@ -6,6 +6,9 @@ import { blogFeedItem, gameFeedItem, storyFeedItem, type EntryWithPubDate } from
const MAX_ITEMS = 8;
export const GET: APIRoute = async ({ site }) => {
if (!site) {
throw new Error("site is required.");
}
const stories = (
(await getCollection(
"stories",
@ -28,7 +31,9 @@ export const GET: APIRoute = async ({ site }) => {
return rss({
title: "Gallery | Bad Manners",
description: "Stories, games, and more by Bad Manners.",
site: site!,
site: site,
xmlns: { atom: "http://www.w3.org/2005/Atom" },
customData: `<link href="${site}" rel="alternate" type="text/html" /><atom:link href="${new URL("feed.xml", site)}" rel="self" type="application/rss+xml" />`,
items: await Promise.all(
[
stories.map(({ data, slug, render }) => ({

View file

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

View file

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