mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-10-27 13:16:30 -04:00
refactor: centralize feed handler creation, use typed route props
This commit is contained in:
6 files changed
+28
-31
No files matched your search
+20
-1
@@ -1,4 +1,5 @@
|
||||
import { Feed, type Item as FeedItem } from "feed";
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
|
||||
import ogImage from "@/app/opengraph-image.jpg";
|
||||
import authorConfig from "@/lib/config/author";
|
||||
@@ -9,7 +10,7 @@ import { getPost, getFrontMatter } from "@/lib/posts";
|
||||
* Returns a `Feed` object, which can then be processed with `feed.rss2()`, `feed.atom1()`, or `feed.json1()`.
|
||||
* @see https://github.com/jpmonette/feed#example
|
||||
*/
|
||||
export const buildFeed = (): Feed => {
|
||||
const buildFeed = (): Feed => {
|
||||
const frontmatter = getFrontMatter();
|
||||
|
||||
const feed = new Feed({
|
||||
@@ -60,3 +61,21 @@ export const buildFeed = (): Feed => {
|
||||
|
||||
return feed;
|
||||
};
|
||||
|
||||
export const createFeedHandler = (
|
||||
feedType: "rss" | "atom" | "json",
|
||||
): { GET: (request: NextRequest) => Promise<Response> } => {
|
||||
return {
|
||||
GET: async () => {
|
||||
const feed = buildFeed();
|
||||
return new NextResponse(
|
||||
feed[feedType === "rss" ? "rss2" : feedType === "atom" ? "atom1" : "json1"](),
|
||||
{
|
||||
headers: {
|
||||
"content-type": `application/${feedType}+xml; charset=utf-8`,
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user