Files
BroadcastChannel/src/pages/rss.xml.js
ccbikai 4fa62bf68d feat: add sanitize-html for content filtering
Enhance RSS feed content safety by integrating sanitize-html to allow specific media tags and attributes, ensuring a secure and controlled presentation of content.
2024-08-07 21:00:55 +08:00

36 lines
1016 B
JavaScript

import rss from '@astrojs/rss'
import sanitizeHtml from 'sanitize-html'
import { getChannelInfo } from '../lib/telegram'
export const prerender = false
export async function GET(Astro) {
const request = Astro.request
const { SITE_URL } = Astro.locals
const channel = await getChannelInfo(Astro)
const posts = channel.posts || []
const url = new URL(request.url)
url.pathname = SITE_URL
return rss({
title: channel.title,
description: channel.description,
site: url.origin,
items: posts.map(item => ({
link: `posts/${item.id}`,
title: item.title,
description: item.description,
pubDate: new Date(item.datetime),
content: sanitizeHtml(item.content, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'video', 'audio']),
allowedAttributes: {
video: ['src', 'width', 'height', 'poster'],
audio: ['src', 'controls'],
img: ['src', 'width', 'height', 'loading'],
},
}),
})),
})
}