export const dynamic = "force-dynamic"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { getLobContent, getLobSidebarItems, type LobChapter, type LobSidebarItem, } from "@/lib/lob"; 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 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("lob", 0, slug); const hlQuote = extractQuoteFromHl(sp, chapter?.paragraphs); if (hlQuote) { return buildOgMeta({ title: BOOK_NAMES["lob"], quote: hlQuote }); } return ogForChapter("lob", ""); } // --------------------------------------------------------------------------- // Page // --------------------------------------------------------------------------- export default async function LobChapterPage({ params, }: { params: Promise<{ chapter: string }>; }) { const { chapter: slug } = await params; const content = await getLobContent(slug); if (!content) notFound(); const sidebarItems = await getLobSidebarItems(); 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 isChapter = "chapter" in content && typeof (content as LobChapter).chapter === "number" && (content as LobChapter).chapter !== null; const chapterNum = isChapter ? (content as LobChapter).chapter : null; return (
← Light of the Bhāgavata

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

{/* Left sidebar */} {/* Main content */}
{/* Top navigation */} {/* Content */}
{content.paragraphs.map((paragraph, i) => paragraph.startsWith("") ? (
) : (
), )}
{/* Bottom navigation */}
); } // --------------------------------------------------------------------------- // Sidebar // --------------------------------------------------------------------------- function LobSidebar({ items, currentSlug, }: { items: LobSidebarItem[]; currentSlug: string; }) { // Split items into groups for visual sections // Front matter: intro-segment items before chapters // Texts: chapter items // (LoB has no back matter) const frontMatterItems: LobSidebarItem[] = []; const textItems: LobSidebarItem[] = []; for (const item of items) { if (item.type === "chapter") { textItems.push(item); } else { frontMatterItems.push(item); } } return ( ); } function SidebarLink({ item, isActive, }: { item: LobSidebarItem; isActive: boolean; }) { let label: string; if (item.type === "chapter" && item.chapter != null) { // Format: "N. Text N" label = `${item.chapter}. Text ${item.chapter}`; } else { label = item.label; } return ( {label} ); } // --------------------------------------------------------------------------- // Prev / Next navigation // --------------------------------------------------------------------------- function LobNav({ prev, next, sidebarItems, currentSlug, }: { prev: LobSidebarItem | null; next: LobSidebarItem | null; sidebarItems: LobSidebarItem[]; currentSlug: string; }) { const mobileNavGroups: MobileNavGroup[] = []; const frontMatterItems: LobSidebarItem[] = []; const textItems: LobSidebarItem[] = []; for (const item of sidebarItems) { if (item.type === "chapter") { textItems.push(item); } else { frontMatterItems.push(item); } } if (frontMatterItems.length > 0) { mobileNavGroups.push({ title: "Front Matter", items: frontMatterItems.map((i) => ({ slug: i.slug, label: i.label, href: `/books/lob/${i.slug}`, type: i.type, })), }); } if (textItems.length > 0) { mobileNavGroups.push({ title: "Texts", items: textItems.map((i) => ({ slug: i.slug, label: i.label, href: `/books/lob/${i.slug}`, type: i.type, })), }); } return (
{prev ? ( {prev.type === "chapter" && prev.chapter != null ? `Text ${prev.chapter}` : prev.label} Previous ) : (
)}
{next ? ( {next.type === "chapter" && next.chapter != null ? `Text ${next.chapter}` : next.label} Next ) : (
)}
); }