export const dynamic = "force-dynamic"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { getSvaContent, getSvaSidebarItems, getNavigableItems, type SvaChapter, type SvaSidebarItem, } from "@/lib/sva"; 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"; // --------------------------------------------------------------------------- // Metadata // --------------------------------------------------------------------------- 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("sva", 0, slug); const hlQuote = extractQuoteFromHl(sp, chapter?.paragraphs); if (hlQuote) { return buildOgMeta({ title: BOOK_NAMES["sva"], quote: hlQuote }); } return ogForChapter("sva", chapter?.title || ""); } // --------------------------------------------------------------------------- // 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(); // Build a flat list of navigable items (skip "parent" type — they're labels, not pages) const navigableItems = getNavigableItems(sidebarItems); const currentIdx = navigableItems.findIndex((item) => item.slug === slug); const prev = currentIdx > 0 ? navigableItems[currentIdx - 1] : null; const next = currentIdx < navigableItems.length - 1 ? navigableItems[currentIdx + 1] : null; // Determine if this is a sub-chapter (has parentChapter) const isSubChapter = "parentChapter" in content && typeof (content as SvaChapter).parentChapter === "number"; const parentChapterNum = isSubChapter ? (content as SvaChapter).parentChapter : null; return (
← Songs of the Vaiṣṇava Ācāryas

{parentChapterNum != null && ( Part {parentChapterNum}: )} {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; }) { // Split items by section const frontMatter = items.filter((i) => i.type === "intro-segment"); const parents = items.filter((i) => i.type === "parent"); const subChapters = items.filter((i) => i.type === "sub-chapter"); return ( ); } function SidebarLink({ item, isActive, }: { item: SvaSidebarItem; isActive: boolean; }) { return ( {item.label} ); } // --------------------------------------------------------------------------- // Prev / Next navigation // --------------------------------------------------------------------------- function SvaNav({ prev, next, sidebarItems, currentSlug, }: { prev: SvaSidebarItem | null; next: SvaSidebarItem | null; sidebarItems: SvaSidebarItem[]; currentSlug: string; }) { const mobileNavGroups: MobileNavGroup[] = []; const frontMatter = sidebarItems.filter((i) => i.type === "intro-segment"); if (frontMatter.length > 0) { mobileNavGroups.push({ title: "Front Matter", items: frontMatter.map((i) => ({ slug: i.slug, label: i.label, href: `/books/sva/${i.slug}`, type: i.type, })), }); } const chapterItems = sidebarItems.filter( (i) => i.type === "parent" || i.type === "sub-chapter", ); if (chapterItems.length > 0) { mobileNavGroups.push({ title: "Songs", items: chapterItems.map((i) => ({ slug: i.slug, label: i.label, href: `/books/sva/${i.slug}`, type: i.type, parentChapter: i.parentChapter, isParent: i.type === "parent", })), }); } return (
{prev ? ( {prev.label} Previous ) : (
)}
{next ? ( {next.label} Next ) : (
)}
); }