// api/routes/rss.ts
import RSS from 'rss';
import { serverQueryContent } from '#content/server';
export default defineEventHandler(async (event) => {
const BASE_URL = 'https://your-domain.com';
const feed = new RSS({
title: 'Your title',
site_url: BASE_URL,
feed_url: `${BASE_URL}/rss.xml`
});
const docs = await serverQueryContent(event)
.sort({ date: -1 })
.where({ _partial: false })
.find();
for (const doc of docs) {
feed.item({
title: doc.title ?? '-',
url: `${BASE_URL}${doc._path}`,
date: doc.date,
description: doc.description
});
}
const feedString = feed.xml({ indent: true });
setHeader(event, 'content-type', 'text/xml');
return feedString;
});