website-astro/src/pages/rss.xml.js

35 lines
1.2 KiB
JavaScript

import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
export async function get(context) {
const articles = await getCollection("articles", ({ data }) => {
return data.lang === "fr" && !data.draft;
});
const fragments = await getCollection("fragments", ({ data }) => {
return data.lang === "fr" && !data.draft;
});
const posts = articles.concat(fragments);
return rss({
// `<title>` field in output xml
title: "Nicolas Arduin",
// `<description>` field in output xml
description: "Articles publiés sur nardu.in",
// Pull in your project "site" from the endpoint context
// https://docs.astro.build/en/reference/api-reference/#contextsite
site: context.site,
// Array of `<item>`s in output xml
// See "Generating items" section for examples using content collections and glob imports
items: posts.map((post) => ({
title: post.data.title,
pubDate: post.data.createdAt,
description: post.data.subtitle,
lang: post.data.lang,
// Compute RSS link from post `slug`
// This example assumes all posts are rendered as `/blog/[slug]` routes
link: `/${post.data.type}/${post.slug}/`,
})),
// (optional) inject custom xml
customData: `<language>fr-fr</language>`,
});
}