Files
Cloud-Blog/server/routes/rss.xml.ts
nurRiyad 072a17132d Add rss feed
Signed-off-by: nurRiyad <asadnurriyad@gmail.com>
2024-10-02 21:53:16 +06:00

38 lines
955 B
TypeScript

import { Feed } from 'feed'
import { serverQueryContent } from '#content/server'
const basePath = 'https://nurriyad.xyz'
export default defineEventHandler(async (event) => {
setHeader(event, 'content-type', 'text/xml')
const docs = await serverQueryContent(event).sort({ date: -1 }).find()
const feed = new Feed({
title: 'Riyad\'s personal blog site',
description: 'Riyad\'s personal blog site',
id: basePath,
link: basePath,
language: 'en',
favicon: `${basePath}/favicon.ico`,
copyright: 'MIT',
author: {
name: 'Al Asad Nur Riyad',
email: 'asadnurriyad@gmail.com',
link: basePath,
},
})
// Add the feed items
docs.forEach((doc) => {
feed.addItem({
title: doc.title || '',
id: basePath + doc._path,
link: basePath + doc._path,
description: doc.description,
content: doc.description,
date: new Date(doc.date),
})
})
return feed.rss2()
})