portfolio/app/feed.xml/route.ts
r-freeman 2e8f5ebdb1
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 2m34s
Fix rss feed
2024-09-17 16:24:35 +01:00

50 lines
1.4 KiB
TypeScript

import {NextRequest} from 'next/server'
import {Feed} from 'feed'
import {getAllArticles} from '@/lib/getAllArticles'
export async function GET(req: NextRequest) {
let siteUrl = process.env.NEXT_PUBLIC_SITE_URL ?? ""
let articles = await getAllArticles()
let author = {
name: 'Ryan Freeman',
email: 'hello@ryanfreeman.dev'
}
let feed = new Feed({
title: author.name,
description: 'Full-stack software engineer who enjoys building cloud-native applications.',
author,
id: siteUrl,
link: siteUrl,
image: `${siteUrl}/favicon.ico`,
favicon: `${siteUrl}/favicon.ico`,
copyright: `Copyright ${(new Date).getFullYear()} Ryan Freeman. All rights reserved.`,
feedLinks: {
rss2: `${siteUrl}/feed.xml`
}
})
for (let article of articles) {
let url = `${siteUrl}/writing/${article.slug}`
let title = article.title
let date = new Date(article.date)
let description = article.description
feed.addItem({
title,
id: url,
link: url,
description,
author: [author],
contributor: [author],
date
})
}
return new Response(feed.rss2(), {
status: 200,
headers: {
'Content-Type': 'application/xml'
}
})
}