Skip to content

Commit

Permalink
feat: add rss feed
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlatz committed Jan 13, 2025
1 parent ab78069 commit 301e7cf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/layouts/Base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const { title, meta_title, description, image, noindex, canonical } =
/>
<meta name="generator" content={Astro.generator} />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="alternate" type="application/rss+xml"
title="Flux RSS du blog Biblys"
href="/rss.xml" />

<!-- google font css -->
<AstroFont
Expand Down
12 changes: 7 additions & 5 deletions src/layouts/partials/Footer.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
---
import Social from "@/components/Social.astro";
import config from "@/config/config.json";
import menu from "@/config/menu.json";
import social from "@/config/social.json";
import {markdownify} from "@/lib/utils/textConverter";
import {FaRssSquare} from "react-icons/fa";
---

<footer class="section bg-theme-dark">
Expand All @@ -18,5 +14,11 @@ import {markdownify} from "@/lib/utils/textConverter";
En savoir plus
</a>
</p>

<p class="mt-12">
<a href="/rss.xml" aria-label="Flux RSS">
<FaRssSquare size="2em" />
</a>
</p>
</div>
</footer>
22 changes: 22 additions & 0 deletions src/pages/rss.xml.ts
Original file line number Diff line number Diff line change
@@ -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: `<language>fr-fr</language>`,
});
}

0 comments on commit 301e7cf

Please sign in to comment.