export const prerender = false;

import rss from '@astrojs/rss';
import { getBlogPosts } from "../../content/config";

export async function GET(context) {
  const lang = context.url.pathname.substring(1,3);
  const posts = await getBlogPosts();
  var blog = posts.filter(
    (post) => post.data.language == lang,
  );

  return rss({
    title: 'Title',
    description: 'Description',
    site: context.site,
    items: blog.map((post) => ({
      title: post.data.title,
      pubDate: post.data.publishDate,
      description: post.data.description,
      // Compute RSS link from post `slug`
      // This example assumes all posts are rendered as `/blog/[slug]` routes
      link: `/${lang}/blog/${post.blog_slug}/`,
    })),
  });
}