summaryrefslogtreecommitdiff
path: root/apps/web/src/app/rss.xml/route.ts
blob: 8602a03fac36c0da852cd4ecd1c9bed0b4cc857d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Feed } from 'feed';
import { getPosts } from '@/lib/blog-query';
import { SITE_INFO } from '../metadata';

export async function GET() {
  const { posts } = await getPosts();
  
  const feed = new Feed({
    title: 'OpenCut Blog',
    description: SITE_INFO.description,
    id: `${SITE_INFO.url}`,
    link: `${SITE_INFO.url}/blog/`,
    language: 'en',
    image: `${SITE_INFO.openGraphImage}`,
    favicon: `${SITE_INFO.favicon}`,
    copyright: `All rights reserved ${new Date().getFullYear()}, ${
      SITE_INFO.title
    }`,
  });

  for (const post of posts) {
    feed.addItem({
        title: post.title,
        id: `${SITE_INFO.url}/blog/${post.slug}`,
        link: `${SITE_INFO.url}/blog/${post.slug}`,
        description: post.description,
        author: post.authors.map((author) => ({
        name: post.name ?? 'OpenCut',
      })),
      date: new Date(post.publishedAt),
      image: post.coverImage,
    });
  });

  return new Response(feed.rss2(), {
    headers: {
      'Content-Type': 'text/xml',
    },
  });
}