diff --git a/app/(app)/books/cc/[lila]/[chapter]/page.tsx b/app/(app)/books/cc/[lila]/[chapter]/page.tsx index 903ed062..c08b3c58 100644 --- a/app/(app)/books/cc/[lila]/[chapter]/page.tsx +++ b/app/(app)/books/cc/[lila]/[chapter]/page.tsx @@ -1,9 +1,26 @@ +export const dynamic = "force-dynamic"; + import type { Metadata } from "next"; -import { redirect } from "next/navigation"; -import { notFound } from "next/navigation"; -import { getChapterVerseIndex } from "@/lib/api"; +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, @@ -24,9 +41,73 @@ export default async function CcChapterPage({ params: Promise<{ lila: string; chapter: string }>; }) { const { lila, chapter } = await params; - const verseIndex = await getChapterVerseIndex("cc", lila, parseInt(chapter)); - if (verseIndex.length === 0) { - notFound(); + 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}`); } - redirect(`/books/cc/${lila}/${chapter}/${verseIndex[0].verse}`); + + return ( +
+ + + ← {lilaInfo.name} + +
+

+ Chapter {chapterNum}: {chapterInfo.title} +

+ +
+
+ +
+

+ Chapter Summary +

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