export const dynamic = "force-dynamic"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { getSsrContent, getSsrSidebarItems, type SsrChapter, type SsrSidebarItem, } from "@/lib/ssr"; 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("ssr", 0, slug); const hlQuote = extractQuoteFromHl(sp, chapter?.paragraphs); if (hlQuote) { return buildOgMeta({ title: BOOK_NAMES["ssr"], quote: hlQuote }); } return ogForChapter("ssr", chapter?.title || ""); } // --------------------------------------------------------------------------- // 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, sidebarItems, currentSlug, }: { prev: SsrSidebarItem | null; next: SsrSidebarItem | null; sidebarItems: SsrSidebarItem[]; currentSlug: string; }) { const mobileNavGroups: MobileNavGroup[] = []; const frontMatter = sidebarItems.filter( (i) => i.type === "intro-segment" && i.slug !== "intro-about-the-author", ); if (frontMatter.length > 0) { mobileNavGroups.push({ title: "Front Matter", items: frontMatter.map((i) => ({ slug: i.slug, label: i.label, href: `/books/ssr/${i.slug}`, type: i.type, })), }); } const chapterItems = sidebarItems.filter( (i) => i.type === "parent" || i.type === "sub-chapter", ); if (chapterItems.length > 0) { mobileNavGroups.push({ title: "Chapters", items: chapterItems.map((i) => ({ slug: i.slug, label: i.label, href: `/books/ssr/${i.slug}`, type: i.type, parentChapter: i.parentChapter, isParent: i.type === "parent", })), }); } const backMatter = sidebarItems.filter( (i) => i.slug === "intro-about-the-author", ); if (backMatter.length > 0) { mobileNavGroups.push({ title: "Back Matter", items: backMatter.map((i) => ({ slug: i.slug, label: i.label, href: `/books/ssr/${i.slug}`, type: i.type, })), }); } return (
{prev ? ( {prev.label} Previous ) : (
)}
{next ? ( {next.label} Next ) : (
)}
); }