export const dynamic = "force-dynamic"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { getRvContent, getRvSidebarItems, type RvChapter, type RvSidebarItem, } from "@/lib/rv"; 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("rv", 0, slug); const hlQuote = extractQuoteFromHl(sp, chapter?.paragraphs); if (hlQuote) { return buildOgMeta({ title: BOOK_NAMES["rv"], quote: hlQuote }); } return ogForChapter("rv", chapter?.title || ""); } // --------------------------------------------------------------------------- // Page // --------------------------------------------------------------------------- export default async function RvChapterPage({ params, }: { params: Promise<{ chapter: string }>; }) { const { chapter: slug } = await params; const content = await getRvContent(slug); if (!content) notFound(); const sidebarItems = await getRvSidebarItems(); 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 RvChapter).chapter === "number" && (content as RvChapter).chapter !== null; const chapterNum = isChapter ? (content as RvChapter).chapter : null; return (
← Rāja-vidyā: The King of Knowledge

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

{/* Left sidebar */} {/* Main content */}
{/* Top navigation */} {/* Content */}
{content.paragraphs.map((paragraph, i) => (
))}
{/* Bottom navigation */}
); } // --------------------------------------------------------------------------- // Sidebar // --------------------------------------------------------------------------- function RvSidebar({ items, currentSlug, }: { items: RvSidebarItem[]; currentSlug: string; }) { const introItems = items.filter((item) => item.type === "intro-segment"); const chapterItems = items.filter((item) => item.type === "chapter"); return ( ); } function SidebarLink({ item, isActive, }: { item: RvSidebarItem; isActive: boolean; }) { return ( {item.label} ); } // --------------------------------------------------------------------------- // Prev / Next navigation // --------------------------------------------------------------------------- function RvNav({ prev, next, sidebarItems, currentSlug, }: { prev: RvSidebarItem | null; next: RvSidebarItem | null; sidebarItems: RvSidebarItem[]; currentSlug: string; }) { const mobileNavGroups: MobileNavGroup[] = []; const introItems = sidebarItems.filter((i) => i.type === "intro-segment"); if (introItems.length > 0) { mobileNavGroups.push({ title: "Front Matter", items: introItems.map((i) => ({ slug: i.slug, label: i.label, href: `/books/rv/${i.slug}`, type: i.type, })), }); } 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/rv/${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 ) : (
)}
); }