export const dynamic = "force-dynamic"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { getOtherDocumentContent, getOtherDocumentMeta, getOtherDocumentSidebarItems, slugToBookCode, type OtherDocumentSidebarItem, } from "@/lib/other-documents"; import { ogForOtherDocument, extractQuoteFromHl, buildOgMeta } from "@/lib/og"; 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<{ slug: string; chapter: string }>; searchParams: Promise>; }): Promise { const { slug, chapter: chapterSlug } = await params; const sp = await searchParams; const bookCode = slugToBookCode(slug); const [meta, content] = await Promise.all([ getOtherDocumentMeta(bookCode), getOtherDocumentContent(bookCode, chapterSlug), ]); const paragraphs = content?.paragraphs; const quote = extractQuoteFromHl(sp, paragraphs); if (quote) { const title = meta?.title ?? slug; const detail = content?.title ?? `Chapter ${chapterSlug}`; return buildOgMeta({ title, detail, quote }); } return ogForOtherDocument(meta?.title ?? slug, content?.title ?? undefined); } // --------------------------------------------------------------------------- // Page // --------------------------------------------------------------------------- export default async function OtherDocumentChapterPage({ params, }: { params: Promise<{ slug: string; chapter: string }>; }) { const { slug, chapter: chapterSlug } = await params; const bookCode = slugToBookCode(slug); const [meta, content, sidebarItems] = await Promise.all([ getOtherDocumentMeta(bookCode), getOtherDocumentContent(bookCode, chapterSlug), getOtherDocumentSidebarItems(bookCode), ]); if (!meta || !content) notFound(); const currentIdx = sidebarItems.findIndex( (item) => item.slug === chapterSlug, ); const prev = currentIdx > 0 ? sidebarItems[currentIdx - 1] : null; const next = currentIdx < sidebarItems.length - 1 ? sidebarItems[currentIdx + 1] : null; return (
← {meta.title}

Chapter {content.chapter}: {content.title}

{/* Left sidebar */} {/* Main content */}
{/* Top navigation */} {/* Content */}
{content.paragraphs.map((paragraph, i) => (
))}
{/* Bottom navigation */}
); } // --------------------------------------------------------------------------- // Sidebar // --------------------------------------------------------------------------- function ChapterSidebar({ items, currentSlug, docSlug, }: { items: OtherDocumentSidebarItem[]; currentSlug: string; docSlug: string; }) { return ( ); } // --------------------------------------------------------------------------- // Prev / Next navigation // --------------------------------------------------------------------------- function ChapterNav({ prev, next, sidebarItems, currentSlug, docSlug, docTitle, }: { prev: OtherDocumentSidebarItem | null; next: OtherDocumentSidebarItem | null; sidebarItems: OtherDocumentSidebarItem[]; currentSlug: string; docSlug: string; docTitle: string; }) { const mobileNavGroups: MobileNavGroup[] = []; if (sidebarItems.length > 0) { mobileNavGroups.push({ title: "Chapters", items: sidebarItems.map((i) => ({ slug: i.slug, label: i.label, href: `/other-documents/${docSlug}/${i.slug}`, type: i.type, })), }); } return (
{prev ? ( Ch. {prev.chapter} Previous ) : (
)}
{next ? ( Ch. {next.chapter} Next ) : (
)}
); }