Add RSS feed functionality and icon to the blog
All checks were successful
Build and Deploy Blog / build-and-deploy-local (push) Successful in 1m13s
All checks were successful
Build and Deploy Blog / build-and-deploy-local (push) Successful in 1m13s
This commit is contained in:
35
app/feed.xml/route.ts
Normal file
35
app/feed.xml/route.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
import RSS from "rss";
|
||||
import { getSortedPostsData } from "@/lib/posts";
|
||||
|
||||
export async function GET() {
|
||||
const feed = new RSS({
|
||||
title: "Gabriel Kaszewski's Blog",
|
||||
description: "A personal blog by Gabriel Kaszewski about technology, programming, and game development.",
|
||||
site_url: "https://blog.gabrielkaszewski.dev",
|
||||
feed_url: "https://blog.gabrielkaszewski.dev/feed.xml",
|
||||
language: "en",
|
||||
pubDate: new Date(),
|
||||
copyright: `© ${new Date().getFullYear()} Gabriel Kaszewski`,
|
||||
});
|
||||
|
||||
const posts = getSortedPostsData();
|
||||
|
||||
posts.forEach((post) => {
|
||||
feed.item({
|
||||
title: post.title,
|
||||
description: post.description,
|
||||
url: `https://blog.gabrielkaszewski.dev/posts/${post.id}`,
|
||||
guid: post.id,
|
||||
date: post.date,
|
||||
});
|
||||
});
|
||||
|
||||
const xml = feed.xml({ indent: true });
|
||||
|
||||
return new Response(xml, {
|
||||
headers: {
|
||||
"Content-Type": "application/xml; charset=utf-8",
|
||||
},
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user