summaryrefslogtreecommitdiff
path: root/src/app/(main)/rss.xml/route.ts
diff options
context:
space:
mode:
authorBertrand Yuan <bert.yuan@outlook.com>2025-12-16 00:15:04 +0800
committerBertrand Yuan <bert.yuan@outlook.com>2025-12-16 00:15:04 +0800
commit785371bb3eccca455e5ce5fccbe9b6e3752a03f6 (patch)
treedd006593448c3500bdcb414af3b4656f7a7683d4 /src/app/(main)/rss.xml/route.ts
parent02ae938c238c9d18448d17a8ec92c0edd8c17463 (diff)
fix(front-end): bug in viewing posts
Diffstat (limited to 'src/app/(main)/rss.xml/route.ts')
-rw-r--r--src/app/(main)/rss.xml/route.ts36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/app/(main)/rss.xml/route.ts b/src/app/(main)/rss.xml/route.ts
index ee06a40..3507948 100644
--- a/src/app/(main)/rss.xml/route.ts
+++ b/src/app/(main)/rss.xml/route.ts
@@ -1,10 +1,10 @@
import { description, title } from '@/app/(main)/layout.config';
import { owner } from '@/app/(main)/layout.config';
import { baseUrl } from '@/lib/constants';
-import { getPosts } from '@/lib/source';
+import { getPublishedPosts } from '@/lib/payload-posts';
import { Feed } from 'feed';
-export const dynamic = 'force-static';
+export const dynamic = 'force-dynamic';
const escapeForXML = (str: string) => {
return str
@@ -15,8 +15,8 @@ const escapeForXML = (str: string) => {
.replace(/'/g, '&apos;');
};
-export const GET = () => {
- const feed = createFeed();
+export const GET = async () => {
+ const feed = await createFeed();
return new Response(feed.atom1(), {
headers: {
@@ -25,7 +25,7 @@ export const GET = () => {
});
};
-function createFeed(): Feed {
+async function createFeed(): Promise<Feed> {
const feed = new Feed({
title,
description,
@@ -39,24 +39,24 @@ function createFeed(): Feed {
updated: new Date(),
});
- const posts = getPosts();
+ const { posts } = await getPublishedPosts({ limit: 1000 });
+
for (const post of posts) {
feed.addItem({
- title: post.data.title,
- description: post.data.description,
+ title: post.title,
+ description: post.description,
link: new URL(post.url, baseUrl).href,
- image: {
- title: post.data.title,
- type: 'image/png',
- url: escapeForXML(
- new URL(`/og/${post.slugs.join('/')}/image.png`, baseUrl.href).href,
- ),
- },
- date: post.data.date,
+ image: post.image
+ ? {
+ title: post.title,
+ type: 'image/png',
+ url: escapeForXML(new URL(post.image, baseUrl.href).href),
+ }
+ : undefined,
+ date: post.date,
author: [
{
- name: post.data.author,
- // link: new URL('/about', baseUrl).href,
+ name: post.author,
},
],
});