export const dynamic = "force-dynamic"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { getDsContent, getDsSidebarItems, type DsChapter, type DsSidebarItem, } from "@/lib/ds"; 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("ds", 0, slug); const hlQuote = extractQuoteFromHl(sp, chapter?.paragraphs); if (hlQuote) { return buildOgMeta({ title: BOOK_NAMES["ds"], quote: hlQuote }); } return ogForChapter("ds", ""); } // --------------------------------------------------------------------------- // Page // --------------------------------------------------------------------------- export default async function DsChapterPage({ params, }: { params: Promise<{ chapter: string }>; }) { const { chapter: slug } = await params; const content = await getDsContent(slug); if (!content) notFound(); const sidebarItems = await getDsSidebarItems(); // 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 DsChapter).parentChapter === "number"; const parentChapterNum = isSubChapter ? (content as DsChapter).parentChapter : null; return (
← Dialectic Spiritualism

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

{/* Left sidebar */} {/* Main content */}
{/* Top navigation */} {/* Content */}
{content.paragraphs.map((paragraph, i) => (
))}
{/* Bottom navigation */}
); } // --------------------------------------------------------------------------- // Sidebar // --------------------------------------------------------------------------- function DsSidebar({ items, currentSlug, }: { items: DsSidebarItem[]; currentSlug: string; }) { // Split items by section const introItems = 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: DsSidebarItem; isActive: boolean; }) { return ( {item.label} ); } // --------------------------------------------------------------------------- // Prev / Next navigation // --------------------------------------------------------------------------- function DsNav({ prev, next, sidebarItems, currentSlug, }: { prev: DsSidebarItem | null; next: DsSidebarItem | null; sidebarItems: DsSidebarItem[]; 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/ds/${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/ds/${i.slug}`, type: i.type, parentChapter: i.parentChapter, isParent: i.type === "parent", })), }); } return (
{prev ? ( {prev.label} Previous ) : (
)}
{next ? ( {next.label} Next ) : (
)}
); }