140 lines
3.9 KiB
TypeScript
140 lines
3.9 KiB
TypeScript
export const dynamic = "force-dynamic";
|
||
|
||
import type { Metadata } from "next";
|
||
import Link from "next/link";
|
||
import { PageHeader } from "@/components/layout/page-header";
|
||
import { notFound } from "next/navigation";
|
||
import { getBookMeta, getSingleVerse, getChapterVerseIndex } from "@/lib/api";
|
||
import { ChapterViewer } from "@/app/(app)/books/chapter-viewer";
|
||
import type { MobileNavGroup } from "@/components/layout/mobile-nav";
|
||
import { ogForVerse, extractQuoteFromHl, buildOgMeta } from "@/lib/og";
|
||
|
||
type ChapterInfo = {
|
||
number: number;
|
||
title: string;
|
||
totalVerses: number;
|
||
};
|
||
|
||
type LilaInfo = {
|
||
key: string;
|
||
name: string;
|
||
totalChapters: number;
|
||
totalVerses: number;
|
||
chapters: ChapterInfo[];
|
||
};
|
||
|
||
export async function generateMetadata({
|
||
params,
|
||
searchParams,
|
||
}: {
|
||
params: Promise<{ lila: string; chapter: string; verse: string }>;
|
||
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
||
}): Promise<Metadata> {
|
||
const { lila, chapter, verse } = await params;
|
||
const sp = await searchParams;
|
||
const v = await getSingleVerse(
|
||
"cc",
|
||
lila,
|
||
parseInt(chapter),
|
||
parseInt(verse),
|
||
);
|
||
const paragraphs = v ? [v.translation, ...v.purport] : undefined;
|
||
const quote = extractQuoteFromHl(sp, paragraphs);
|
||
if (quote) {
|
||
const bookTitle = "Śrī Caitanya-caritāmṛta";
|
||
return buildOgMeta({
|
||
title: bookTitle,
|
||
detail: `${lila.charAt(0).toUpperCase() + lila.slice(1)}, Chapter ${chapter}, Verse ${verse}`,
|
||
quote,
|
||
});
|
||
}
|
||
return ogForVerse("cc", {
|
||
division: lila,
|
||
chapter: parseInt(chapter),
|
||
verse: parseInt(verse),
|
||
});
|
||
}
|
||
|
||
export default async function CcVersePage({
|
||
params,
|
||
}: {
|
||
params: Promise<{ lila: string; chapter: string; verse: string }>;
|
||
}) {
|
||
const { lila, chapter, verse } = await params;
|
||
|
||
const meta = await getBookMeta("cc");
|
||
if (!meta) notFound();
|
||
|
||
const lilas = meta.lilas as LilaInfo[] | undefined;
|
||
const lilaInfo = lilas?.find((l) => l.key === lila);
|
||
if (!lilaInfo) notFound();
|
||
|
||
const chapterInfo = lilaInfo.chapters.find(
|
||
(ch) => ch.number === parseInt(chapter),
|
||
);
|
||
if (!chapterInfo) notFound();
|
||
|
||
const verseIndex = await getChapterVerseIndex("cc", lila, parseInt(chapter));
|
||
if (verseIndex.length === 0) notFound();
|
||
|
||
const requestedVerse = parseInt(verse);
|
||
const verseData = await getSingleVerse(
|
||
"cc",
|
||
lila,
|
||
parseInt(chapter),
|
||
requestedVerse,
|
||
);
|
||
if (!verseData) notFound();
|
||
|
||
// Build mobile nav groups from verse index
|
||
const mobileNavGroups: MobileNavGroup[] = [];
|
||
if (verseIndex.length > 0) {
|
||
mobileNavGroups.push({
|
||
title: "Verses",
|
||
items: verseIndex.map((v) => ({
|
||
slug: String(v.verse),
|
||
label: v.verseEnd
|
||
? `Verse ${chapter}.${v.verse}–${v.verseEnd}`
|
||
: `Verse ${chapter}.${v.verse}`,
|
||
href: `/books/cc/${lila}/${chapter}/${v.verse}`,
|
||
type: "verse",
|
||
})),
|
||
});
|
||
}
|
||
|
||
return (
|
||
<div className="min-h-screen bg-background">
|
||
<PageHeader sticky>
|
||
<Link
|
||
href={`/books/cc/${lila}`}
|
||
className="text-sm text-muted-foreground hover:text-foreground"
|
||
>
|
||
← {lilaInfo.name}
|
||
</Link>
|
||
<h1 className="mt-2 text-2xl font-bold text-foreground">
|
||
Chapter {chapter}: {chapterInfo.title}
|
||
</h1>
|
||
</PageHeader>
|
||
|
||
<div className="max-w-5xl mx-auto flex">
|
||
<ChapterViewer
|
||
initialVerse={verseData}
|
||
initialVerseNum={requestedVerse}
|
||
verseIndex={verseIndex.map((v) => ({
|
||
verse: v.verse,
|
||
verseEnd: v.verseEnd ?? undefined,
|
||
reference: v.reference,
|
||
}))}
|
||
book="cc"
|
||
division={lila}
|
||
chapter={parseInt(chapter)}
|
||
showBengali={true}
|
||
basePath={`/books/cc/${lila}/${chapter}`}
|
||
mobileNavGroups={mobileNavGroups}
|
||
mobileNavBookTitle={`Chapter ${chapter}: ${chapterInfo.title}`}
|
||
/>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|