Skip to content

Commit

Permalink
fix(rss): use "application/rss+xml" as default content type and allow…
Browse files Browse the repository at this point in the history
… set custom charset

According to https://www.rssboard.org/rss-mime-type-application.txt
The MIME type for RSS feed should be "application/rss+xml"
It also need to set the charset in content type for non-english content
  • Loading branch information
kunyan committed Dec 5, 2024
1 parent 8a551c1 commit 32753ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-rocks-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/rss': patch
---

use standard rss content type
9 changes: 7 additions & 2 deletions packages/astro-rss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export type RSSOptions = {
/** Specify custom data in opening of file */
customData?: z.infer<typeof rssOptionsValidator>['customData'];
trailingSlash?: z.infer<typeof rssOptionsValidator>['trailingSlash'];
/**
* Specify the response charset. default is utf-8
*/
charset?: z.infer<typeof rssOptionsValidator>['charset'];
};

export type RSSFeedItem = {
Expand Down Expand Up @@ -83,13 +87,14 @@ const rssOptionsValidator = z.object({
stylesheet: z.union([z.string(), z.boolean()]).optional(),
customData: z.string().optional(),
trailingSlash: z.boolean().default(true),
charset: z.string().default('utf-8')
});

export default async function getRssResponse(rssOptions: RSSOptions): Promise<Response> {
export default async function getRssResponse({charset, ...rssOptions}: RSSOptions): Promise<Response> {
const rssString = await getRssString(rssOptions);
return new Response(rssString, {
headers: {
'Content-Type': 'application/xml',
'Content-Type': `application/rss+xml; charset=${charset}`,
},
});
}
Expand Down

0 comments on commit 32753ea

Please sign in to comment.