Files
spsays-training/app/(app)/(reader)/books/sb/[canto]/[chapter]/page.tsx
T

31 lines
880 B
TypeScript

import type { Metadata } from "next";
import { redirect } from "next/navigation";
import { notFound } from "next/navigation";
import { getChapterVerseIndex } from "@/lib/api";
import { buildOgMeta } from "@/lib/og";
export async function generateMetadata({
params,
}: {
params: Promise<{ canto: string; chapter: string }>;
}): Promise<Metadata> {
const { canto, chapter } = await params;
return buildOgMeta({
title: "Śrīmad-Bhāgavatam",
detail: `Canto ${canto}, Chapter ${chapter}`,
});
}
export default async function SbChapterPage({
params,
}: {
params: Promise<{ canto: string; chapter: string }>;
}) {
const { canto, chapter } = await params;
const verseIndex = await getChapterVerseIndex("sb", canto, parseInt(chapter));
if (verseIndex.length === 0) {
notFound();
}
redirect(`/books/sb/${canto}/${chapter}/${verseIndex[0].verse}`);
}