import Link from "next/link"; import { notFound } from "next/navigation"; import { getSsrContent, getSsrSidebarItems, type SsrChapter, type SsrSidebarItem, } from "@/lib/ssr"; 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"; // --------------------------------------------------------------------------- // Page // --------------------------------------------------------------------------- export default async function SsrChapterPage({ params, }: { params: Promise<{ chapter: string }>; }) { const { chapter: slug } = await params; const content = await getSsrContent(slug); if (!content) notFound(); const sidebarItems = await getSsrSidebarItems(); // Build a flat list of navigable items (skip "parent" type — they're labels, not pages) const navigableItems = sidebarItems.filter((item) => item.type !== "parent"); 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 and is type "chapter"/"sub-chapter") const isSubChapter = "parentChapter" in content && typeof (content as SsrChapter).parentChapter === "number"; const parentChapterNum = isSubChapter ? (content as SsrChapter).parentChapter : null; return (
← The Science of Self-Realization

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

{/* Left sidebar */} {/* Main content */}
{/* Top navigation */} {/* Content */}
{content.paragraphs.map((paragraph, i) => (
))}
{/* Bottom navigation */}
); } // --------------------------------------------------------------------------- // Sidebar // --------------------------------------------------------------------------- function SsrSidebar({ items, currentSlug, }: { items: SsrSidebarItem[]; currentSlug: string; }) { // Split items by section const frontMatter = items.filter( (i) => i.type === "intro-segment" && i.slug !== "intro-about-the-author", ); const parents = items.filter((i) => i.type === "parent"); const subChapters = items.filter((i) => i.type === "sub-chapter"); const backMatter = items.filter((i) => i.slug === "intro-about-the-author"); return ( ); } function SidebarLink({ item, isActive, }: { item: SsrSidebarItem; isActive: boolean; }) { return ( {item.label} ); } // --------------------------------------------------------------------------- // Prev / Next navigation // --------------------------------------------------------------------------- function SsrNav({ prev, next, }: { prev: SsrSidebarItem | null; next: SsrSidebarItem | null; }) { return (
{prev ? ( {prev.label} Previous ) : (
)} {next ? ( {next.label} Next ) : (
)}
); }