import Link from "next/link"; import { notFound } from "next/navigation"; import { getSvaContent, getSvaSidebarItems, type SvaChapter, type SvaSidebarItem, } from "@/lib/sva"; import { PageHeader } from "@/components/page-header"; 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/mobile-nav"; // --------------------------------------------------------------------------- // Page // --------------------------------------------------------------------------- export default async function SvaChapterPage({ params, }: { params: Promise<{ chapter: string }>; }) { const { chapter: slug } = await params; const content = await getSvaContent(slug); if (!content) notFound(); const sidebarItems = await getSvaSidebarItems(); 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 SvaChapter).chapter === "number" && (content as SvaChapter).chapter !== null; const chapterNum = isChapter ? (content as SvaChapter).chapter : null; return (
← Songs of the Vaiṣṇava Ācāryas

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

{/* Left sidebar */} {/* Main content */}
{/* Top navigation */} {/* Content */}
{content.paragraphs.map((paragraph, i) => (
))}
{/* Bottom navigation */}
); } // --------------------------------------------------------------------------- // Sidebar // --------------------------------------------------------------------------- function SvaSidebar({ items, currentSlug, }: { items: SvaSidebarItem[]; currentSlug: string; }) { const frontMatterItems: SvaSidebarItem[] = []; const chapterItems: SvaSidebarItem[] = []; const backMatterItems: SvaSidebarItem[] = []; let pastChapters = false; for (const item of items) { if (item.type === "chapter") { pastChapters = true; chapterItems.push(item); } else if (!pastChapters) { frontMatterItems.push(item); } else { backMatterItems.push(item); } } return ( ); } function SidebarLink({ item, isActive, }: { item: SvaSidebarItem; isActive: boolean; }) { let label: string; if (item.type === "chapter" && item.chapter != null) { // Extract just the title portion after "Part N: " const titlePart = item.label.replace(/^Part \d+:\s*/, ""); label = `${item.chapter}. ${titlePart}`; } else { label = item.label; } return ( {label} ); } // --------------------------------------------------------------------------- // Prev / Next navigation // --------------------------------------------------------------------------- function SvaNav({ prev, next, sidebarItems, currentSlug, }: { prev: SvaSidebarItem | null; next: SvaSidebarItem | null; sidebarItems: SvaSidebarItem[]; currentSlug: string; }) { const mobileNavGroups: MobileNavGroup[] = []; const frontMatterItems: SvaSidebarItem[] = []; const chapterItems: SvaSidebarItem[] = []; const backMatterItems: SvaSidebarItem[] = []; let pastChapters = false; for (const item of sidebarItems) { if (item.type === "chapter") { pastChapters = true; chapterItems.push(item); } else if (!pastChapters) { frontMatterItems.push(item); } else { backMatterItems.push(item); } } if (frontMatterItems.length > 0) { mobileNavGroups.push({ title: "Front Matter", items: frontMatterItems.map((i) => ({ slug: i.slug, label: i.label, href: `/books/sva/${i.slug}`, type: i.type, })), }); } if (chapterItems.length > 0) { mobileNavGroups.push({ title: "Parts", items: chapterItems.map((i) => ({ slug: i.slug, label: i.label, href: `/books/sva/${i.slug}`, type: i.type, })), }); } if (backMatterItems.length > 0) { mobileNavGroups.push({ title: "Back Matter", items: backMatterItems.map((i) => ({ slug: i.slug, label: i.label, href: `/books/sva/${i.slug}`, type: i.type, })), }); } return (
{prev ? ( {prev.type === "chapter" && prev.chapter != null ? `Part ${prev.chapter}` : prev.label} Previous ) : (
)}
{next ? ( {next.type === "chapter" && next.chapter != null ? `Part ${next.chapter}` : next.label} Next ) : (
)}
); }