From 8d5ad0971764b05bc1d5efce633ffd3239d7f749 Mon Sep 17 00:00:00 2001 From: nurRiyad Date: Thu, 13 Mar 2025 03:30:24 +0600 Subject: [PATCH] Add RSS feed generation and TypeScript configuration for server routes --- server/routes/rss.xml.ts | 37 +++++++++++++++++++++++++++++++++++++ server/tsconfig.json | 3 +++ 2 files changed, 40 insertions(+) create mode 100644 server/routes/rss.xml.ts create mode 100644 server/tsconfig.json diff --git a/server/routes/rss.xml.ts b/server/routes/rss.xml.ts new file mode 100644 index 0000000..4aea89d --- /dev/null +++ b/server/routes/rss.xml.ts @@ -0,0 +1,37 @@ +import { Feed } from 'feed' + +const basePath = 'https://nurriyad.com' + +export default defineEventHandler(async (event) => { + setHeader(event, 'content-type', 'text/xml') + const docs = await queryCollection(event, 'content').all() + 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) => { + // console.log(doc) + feed.addItem({ + title: doc.title || '', + id: basePath + doc.path, + link: basePath + doc.path, + description: doc.description, + content: doc.description, + date: new Date(doc.meta?.date as string), + }) + }) + + return feed.rss2() +}) diff --git a/server/tsconfig.json b/server/tsconfig.json new file mode 100644 index 0000000..b9ed69c --- /dev/null +++ b/server/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../.nuxt/tsconfig.server.json" +}