Skip to content

Commit 72b6553

Browse files
author
rayepeng
committed
fix rss
1 parent da1edac commit 72b6553

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/pages/feed.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function stripInvalidXmlChars(str: string): string {
1919
export async function GET(context: APIContext) {
2020
const blog = await getSortedPosts();
2121

22-
return rss({
22+
const rssResponse = await rss({
2323
title: siteConfig.title,
2424
description: siteConfig.subtitle || "No description",
2525
site: context.site ?? "https://fuwari.vercel.app",
@@ -39,4 +39,12 @@ export async function GET(context: APIContext) {
3939
}),
4040
customData: `<language>${siteConfig.lang}</language>`,
4141
});
42+
43+
// 手动设置 Content-Type 头,确保浏览器识别为 XML
44+
return new Response(rssResponse.body, {
45+
status: 200,
46+
headers: {
47+
"Content-Type": "application/xml; charset=utf-8",
48+
},
49+
});
4250
}

src/pages/rss.xml.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function stripInvalidXmlChars(str: string): string {
1919
export async function GET(context: APIContext) {
2020
const blog = await getSortedPosts();
2121

22-
return rss({
22+
const rssResponse = await rss({
2323
title: siteConfig.title,
2424
description: siteConfig.subtitle || "No description",
2525
site: context.site ?? "https://fuwari.vercel.app",
@@ -39,4 +39,12 @@ export async function GET(context: APIContext) {
3939
}),
4040
customData: `<language>${siteConfig.lang}</language>`,
4141
});
42+
43+
// 手动设置 Content-Type 头,确保浏览器识别为 XML
44+
return new Response(rssResponse.body, {
45+
status: 200,
46+
headers: {
47+
"Content-Type": "application/xml; charset=utf-8",
48+
},
49+
});
4250
}

0 commit comments

Comments
 (0)