export const dynamic = "force-dynamic"; import type { Metadata } from "next"; import Link from "next/link"; import { redirect, notFound } from "next/navigation"; import { ChevronRight } from "lucide-react"; import { getBookMeta, getProseChapter, getChapterVerseIndex } from "@/lib/api"; import { CC_LILAS } from "@/lib/constants"; import { buildOgMeta } from "@/lib/og"; import { PageHeader } from "@/components/layout/page-header"; import { Card, CardContent } from "@/components/ui/card"; import { buttonVariants } from "@/components/ui/button"; import { FindInPage } from "@/components/layout/find-in-page"; import { cn } from "@/lib/utils"; 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, }: { params: Promise<{ lila: string; chapter: string }>; }): Promise { const { lila, chapter } = await params; const lilaName = CC_LILAS[lila] || lila; return buildOgMeta({ title: "Śrī Caitanya-caritāmṛta", detail: `${lilaName}, Chapter ${chapter}`, }); } export default async function CcChapterPage({ params, }: { params: Promise<{ lila: string; chapter: string }>; }) { const { lila, chapter } = await params; const chapterNum = parseInt(chapter); const [meta, summary, verseIndex] = await Promise.all([ getBookMeta("cc"), getProseChapter("cc", 0, `${lila}-${chapterNum}`), getChapterVerseIndex("cc", lila, chapterNum), ]); if (!meta) notFound(); const lilaInfo = (meta.lilas as LilaInfo[] | undefined)?.find( (l) => l.key === lila, ); if (!lilaInfo) notFound(); const chapterInfo = lilaInfo.chapters.find((ch) => ch.number === chapterNum); if (!chapterInfo) notFound(); if (verseIndex.length === 0) notFound(); const firstVerse = verseIndex[0].verse; // Chapters without a summary (e.g. Ādi 7) go straight to the verses. if (!summary || summary.paragraphs.length === 0) { redirect(`/books/cc/${lila}/${chapterNum}/${firstVerse}`); } return (
← {lilaInfo.name}

Chapter {chapterNum}: {chapterInfo.title}

Chapter Summary

{summary.paragraphs.map((paragraph, i) => (
))}
Read the chapter
); }