mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
fix: add error handling
This commit is contained in:
@@ -3,38 +3,44 @@ import { getPosts } from '@/lib/blog-query';
|
|||||||
import { SITE_INFO } from '../metadata';
|
import { SITE_INFO } from '../metadata';
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const { posts } = await getPosts();
|
try {
|
||||||
|
const { posts } = await getPosts();
|
||||||
|
|
||||||
const feed = new Feed({
|
const feed = new Feed({
|
||||||
title: 'OpenCut Blog',
|
title: 'OpenCut Blog',
|
||||||
description: SITE_INFO.description,
|
description: SITE_INFO.description,
|
||||||
id: `${SITE_INFO.url}`,
|
id: `${SITE_INFO.url}`,
|
||||||
link: `${SITE_INFO.url}/blog/`,
|
link: `${SITE_INFO.url}/blog/`,
|
||||||
language: 'en',
|
language: 'en',
|
||||||
image: `${SITE_INFO.openGraphImage}`,
|
image: `${SITE_INFO.openGraphImage}`,
|
||||||
favicon: `${SITE_INFO.favicon}`,
|
favicon: `${SITE_INFO.favicon}`,
|
||||||
copyright: `All rights reserved ${new Date().getFullYear()}, ${
|
copyright: `All rights reserved ${new Date().getFullYear()}, ${
|
||||||
SITE_INFO.title
|
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(), {
|
for (const post of posts) {
|
||||||
headers: {
|
feed.addItem({
|
||||||
'Content-Type': 'text/xml',
|
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: author.name,
|
||||||
|
})),
|
||||||
|
date: new Date(post.publishedAt),
|
||||||
|
image: post.coverImage || SITE_INFO.openGraphImage,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(feed.rss2(), {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'text/xml',
|
||||||
|
'Cache-Control': 'public, max-age=86400, stale-while-revalidate',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error generating RSS feed', error);
|
||||||
|
return new Response('Internal Server Error', { status: 500 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user