Missing these from earlier commit
This commit is contained in:
parent
418b3e4a3f
commit
cea7376e48
40
src/app/api/feed/route.ts
Normal file
40
src/app/api/feed/route.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import RSS from "rss";
|
||||||
|
import { subDays } from "date-fns";
|
||||||
|
import { fetchChaptersRSS } from "@/lib/api";
|
||||||
|
import { Chapter } from "@/lib/types";
|
||||||
|
|
||||||
|
|
||||||
|
const BASE_URL = process.env.BASE_URL || "http://localhost:3000";
|
||||||
|
|
||||||
|
export async function GET(){
|
||||||
|
const now = new Date();
|
||||||
|
const yesterday = subDays(now, 1);
|
||||||
|
|
||||||
|
const data = await fetchChaptersRSS();
|
||||||
|
|
||||||
|
const feed = new RSS({
|
||||||
|
title: "Null Translation Group",
|
||||||
|
description: "Null Translation Group main hub",
|
||||||
|
site_url: BASE_URL,
|
||||||
|
feed_url: `${BASE_URL}/api/feed`,
|
||||||
|
language: "en",
|
||||||
|
});
|
||||||
|
|
||||||
|
data.forEach((chapter: Chapter) => {
|
||||||
|
feed.item({
|
||||||
|
title: chapter.book?.title + " - Chapter " + chapter.number + " " + chapter.title,
|
||||||
|
description: "Daily chapter release for " + chapter.book?.title,
|
||||||
|
url: `${BASE_URL}/books/${chapter.book?.documentId}/chapters/${chapter.documentId}`,
|
||||||
|
date: chapter.release_datetime,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const xml = feed.xml({ indent: true });
|
||||||
|
|
||||||
|
return new Response(xml, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/xml",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
5
src/app/feed/page.tsx
Normal file
5
src/app/feed/page.tsx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
|
export default function FeedRedirect() {
|
||||||
|
redirect('/api/feed');
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user