aboutsummaryrefslogtreecommitdiff
path: root/src/pages/blog.xml.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/blog.xml.ts')
-rw-r--r--src/pages/blog.xml.ts36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/pages/blog.xml.ts b/src/pages/blog.xml.ts
index 44233b3..2b111d0 100644
--- a/src/pages/blog.xml.ts
+++ b/src/pages/blog.xml.ts
@@ -1,18 +1,42 @@
import rss from "@astrojs/rss";
+import type { APIContext, APIRoute } from "astro";
import { getCollection } from "astro:content";
-export async function GET(context: any) {
- const collection = await getCollection("blog");
+const spanishPubDate = (date: Date): string => {
+ const options: Intl.DateTimeFormatOptions = {
+ year: "numeric",
+ month: "long",
+ day: "numeric",
+ weekday: "long",
+ };
+
+ return date.toLocaleDateString("es-ES", options);
+}
+
+export const GET: APIRoute = async (context) => {
+ const collection = (await getCollection("blog"))
+ .filter((post) => post.data.publishedAt && post.data.title && post.data.description)
+ .sort((a, b) => {
+ return new Date(b.data.publishedAt).getTime() - new Date(a.data.publishedAt).getTime();
+ })
+ .slice(0, 20); // Limit to the latest 20 posts
return rss({
title: "Blog de Ariel Costas",
description: "Artículos del blog de Ariel Costas",
- site: context.site,
- items: collection.map((post: any) => ({
+ site: context.site!,
+ customData: `<link rel="self" type="application/rss+xml" href="${context.url}" />`,
+ xmlns: {
+ "cdrss": "urn:costas.dev#rss",
+ },
+ items: collection.map((post) => ({
title: post.data.title,
- link: `${context.site}blog/${post.slug}`,
- description: post.data.metaDescription,
+ link: `${context.url.origin}/blog/${post.id}`,
+ description: post.data.description,
pubDate: post.data.publishedAt,
+ categories: post.data.tags,
+ customData: `<cdrss:spanishPubDate>${spanishPubDate(post.data.publishedAt)}</cdrss:spanishPubDate>`,
})),
+ stylesheet: "/rss/styles.xsl"
});
}