From 1b8814d9464aec23bc4db9466201adb33669e556 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Latzarus?=
Date: Mon, 13 Jan 2025 09:13:18 +0100
Subject: [PATCH] feat: add rss feed
---
src/layouts/Base.astro | 3 +++
src/layouts/partials/Footer.astro | 12 +++++++-----
src/pages/rss.xml.ts | 22 ++++++++++++++++++++++
3 files changed, 32 insertions(+), 5 deletions(-)
create mode 100644 src/pages/rss.xml.ts
diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro
index 11982da..d51c281 100755
--- a/src/layouts/Base.astro
+++ b/src/layouts/Base.astro
@@ -60,6 +60,9 @@ const { title, meta_title, description, image, noindex, canonical } =
/>
+
@@ -18,5 +14,11 @@ import {markdownify} from "@/lib/utils/textConverter";
En savoir plus
+
+
+
+
+
+
diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts
new file mode 100644
index 0000000..3e14659
--- /dev/null
+++ b/src/pages/rss.xml.ts
@@ -0,0 +1,22 @@
+import rss from '@astrojs/rss';
+import config from '@/config/config.json';
+import {getCollection} from 'astro:content';
+import {sortByDate} from "../lib/utils/sortFunctions";
+
+// noinspection JSUnusedGlobalSymbols
+export async function GET(context: { site: any; }) {
+ const posts = await getCollection('posts');
+ const sortedPosts = sortByDate(posts);
+ return rss({
+ title: config.site.title,
+ description: config.metadata.meta_description,
+ site: context.site,
+ items: sortedPosts.map((post) => ({
+ title: post.data.title,
+ pubDate: post.data.date,
+ description: post.data.description,
+ link: `/posts/${post.slug}`,
+ })),
+ customData: `fr-fr`,
+ });
+}