import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { getCbhcContent, getCbhcSidebarItems, type CbhcChapter, type CbhcSidebarItem, } from "@/lib/cbhc"; import { getProseChapter } from "@/lib/api"; import { ogForChapter, extractQuoteFromHl, buildOgMeta } from "@/lib/og"; import { BOOK_NAMES } from "@/lib/constants"; import { PageHeader } from "@/components/layout/page-header"; import { JsonLd } from "@/components/seo/json-ld"; import { articleJsonLd } from "@/lib/jsonld"; import { Card, CardContent } from "@/components/ui/card"; import { buttonVariants } from "@/components/ui/button"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { cn } from "@/lib/utils"; import { MobileNav, type MobileNavGroup } from "@/components/layout/mobile-nav"; import { FindInPage } from "@/components/layout/find-in-page"; export const dynamic = "force-dynamic"; export async function generateMetadata({ params, searchParams, }: { params: Promise<{ chapter: string }>; searchParams: Promise>; }): Promise { const { chapter: slug } = await params; const sp = await searchParams; const chapter = await getProseChapter("cbhc", 0, slug); const hlQuote = extractQuoteFromHl(sp, chapter?.paragraphs); if (hlQuote) { return buildOgMeta({ title: BOOK_NAMES["cbhc"], quote: hlQuote }); } return ogForChapter("cbhc", ""); } // --------------------------------------------------------------------------- // Page // --------------------------------------------------------------------------- export default async function CbhcChapterPage({ params, }: { params: Promise<{ chapter: string }>; }) { const { chapter: slug } = await params; const content = await getCbhcContent(slug); if (!content) notFound(); const sidebarItems = await getCbhcSidebarItems(); const currentIdx = sidebarItems.findIndex((item) => item.slug === slug); const prev = currentIdx > 0 ? sidebarItems[currentIdx - 1] : null; const next = currentIdx < sidebarItems.length - 1 ? sidebarItems[currentIdx + 1] : null; // Build the page title const chapterNum = (content as CbhcChapter).chapter ?? null; return (
← Śrī Caitanya-bhāgavata Commentary

{chapterNum != null && ( Chapter {chapterNum}: )} {content.title}

{/* Left sidebar */} {/* Main content */}
{/* Top navigation */} {/* Content */}
{content.paragraphs.map((paragraph, i) => (
))}
{/* Bottom navigation */}
); } // --------------------------------------------------------------------------- // Sidebar // --------------------------------------------------------------------------- function CbhcSidebar({ items, currentSlug, }: { items: CbhcSidebarItem[]; currentSlug: string; }) { const chapterItems = items.filter((item) => item.type === "chapter"); return ( ); } function SidebarLink({ item, isActive, }: { item: CbhcSidebarItem; isActive: boolean; }) { const label = item.label; return ( {label} ); } // --------------------------------------------------------------------------- // Prev / Next navigation // --------------------------------------------------------------------------- function CbhcNav({ prev, next, sidebarItems, currentSlug, }: { prev: CbhcSidebarItem | null; next: CbhcSidebarItem | null; sidebarItems: CbhcSidebarItem[]; currentSlug: string; }) { const mobileNavGroups: MobileNavGroup[] = []; const chapterItems = sidebarItems.filter((i) => i.type === "chapter"); if (chapterItems.length > 0) { mobileNavGroups.push({ title: "Chapters", items: chapterItems.map((i) => ({ slug: i.slug, label: i.label, href: `/books/cbhc/${i.slug}`, type: i.type, })), }); } return (
{prev ? ( {prev.type === "chapter" && prev.chapter != null ? `Ch. ${prev.chapter}` : prev.label} Previous ) : (
)}
{next ? ( {next.type === "chapter" && next.chapter != null ? `Ch. ${next.chapter}` : next.label} Next ) : (
)}
); }