Files
mypage/app/feed.xml/route.ts
RJ 3d79cab89a
Some checks failed
Build and Deploy Next.js Blog to Production / 🔍 Code Quality Checks (push) Failing after 18s
Build and Deploy Next.js Blog to Production / 🏗️ Build and Push Docker Image (push) Has been skipped
Build and Deploy Next.js Blog to Production / 🚀 Deploy to Production (push) Has been skipped
📄 production optimizations
2025-12-02 12:39:11 +02:00

42 lines
1.4 KiB
TypeScript

import { getAllPosts } from '@/lib/markdown'
import { NextResponse } from 'next/server'
export async function GET() {
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3030'
const posts = await getAllPosts(false)
const rss = `<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>My Blog - Tech, Development & More</title>
<link>${baseUrl}</link>
<description>Personal blog about software development, technology, and interesting projects</description>
<language>ro-RO</language>
<lastBuildDate>${new Date().toUTCString()}</lastBuildDate>
<atom:link href="${baseUrl}/feed.xml" rel="self" type="application/rss+xml"/>
${posts
.slice(0, 20)
.map(post => {
const postUrl = `${baseUrl}/blog/${post.slug}`
return `
<item>
<title><![CDATA[${post.frontmatter.title}]]></title>
<link>${postUrl}</link>
<guid isPermaLink="true">${postUrl}</guid>
<description><![CDATA[${post.frontmatter.description}]]></description>
<pubDate>${new Date(post.frontmatter.date).toUTCString()}</pubDate>
<author>${post.frontmatter.author}</author>
</item>`
})
.join('')}
</channel>
</rss>`
return new NextResponse(rss, {
headers: {
'Content-Type': 'application/xml',
'Cache-Control': 'public, s-maxage=3600, stale-while-revalidate',
},
})
}