343 lines
9.9 KiB
TypeScript
343 lines
9.9 KiB
TypeScript
export const dynamic = "force-dynamic";
|
|
|
|
import type { Metadata } from "next";
|
|
import Link from "next/link";
|
|
import { notFound } from "next/navigation";
|
|
import {
|
|
getLobContent,
|
|
getLobSidebarItems,
|
|
type LobChapter,
|
|
type LobSidebarItem,
|
|
} from "@/lib/lob";
|
|
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";
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
searchParams,
|
|
}: {
|
|
params: Promise<{ chapter: string }>;
|
|
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
|
}): Promise<Metadata> {
|
|
const { chapter: slug } = await params;
|
|
const sp = await searchParams;
|
|
const chapter = await getProseChapter("lob", 0, slug);
|
|
const hlQuote = extractQuoteFromHl(sp, chapter?.paragraphs);
|
|
if (hlQuote) {
|
|
return buildOgMeta({ title: BOOK_NAMES["lob"], quote: hlQuote });
|
|
}
|
|
return ogForChapter("lob", "");
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Page
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export default async function LobChapterPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ chapter: string }>;
|
|
}) {
|
|
const { chapter: slug } = await params;
|
|
|
|
const content = await getLobContent(slug);
|
|
if (!content) notFound();
|
|
|
|
const sidebarItems = await getLobSidebarItems();
|
|
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 LobChapter).chapter === "number" &&
|
|
(content as LobChapter).chapter !== null;
|
|
const chapterNum = isChapter ? (content as LobChapter).chapter : null;
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<JsonLd data={articleJsonLd({ path: `/books/lob/${slug}`, headline: content.title, description: content.paragraphs?.[0], isPartOf: "Light of the Bhāgavata" })} />
|
|
<PageHeader sticky>
|
|
<Link
|
|
href="/books/lob"
|
|
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
|
|
>
|
|
← Light of the Bhāgavata
|
|
</Link>
|
|
<div className="mt-3 flex items-start justify-between gap-3">
|
|
<h1 className="text-2xl font-bold text-foreground">
|
|
{chapterNum != null && (
|
|
<span className="text-primary">Text {chapterNum}: </span>
|
|
)}
|
|
{content.title}
|
|
</h1>
|
|
<FindInPage targetId="book-content" className="shrink-0 mt-0.5" />
|
|
</div>
|
|
</PageHeader>
|
|
|
|
<div className="max-w-5xl mx-auto flex">
|
|
{/* Left sidebar */}
|
|
<LobSidebar items={sidebarItems} currentSlug={slug} />
|
|
|
|
{/* Main content */}
|
|
<main className="flex-1 min-w-0 px-6 py-8 space-y-8">
|
|
{/* Top navigation */}
|
|
<LobNav
|
|
prev={prev}
|
|
next={next}
|
|
sidebarItems={sidebarItems}
|
|
currentSlug={slug}
|
|
/>
|
|
|
|
{/* Content */}
|
|
<Card id="book-content">
|
|
<CardContent className="py-8 px-6 sm:px-8">
|
|
<div className="space-y-4">
|
|
{content.paragraphs.map((paragraph, i) =>
|
|
paragraph.startsWith("<b>") ? (
|
|
<div
|
|
key={i}
|
|
className="text-base text-foreground leading-relaxed font-medium bg-muted/30 rounded-lg p-4 border border-border/50"
|
|
dangerouslySetInnerHTML={{ __html: paragraph }}
|
|
/>
|
|
) : (
|
|
<div
|
|
key={i}
|
|
className="text-base text-foreground leading-relaxed"
|
|
dangerouslySetInnerHTML={{ __html: paragraph }}
|
|
/>
|
|
),
|
|
)}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
{/* Bottom navigation */}
|
|
<LobNav
|
|
prev={prev}
|
|
next={next}
|
|
sidebarItems={sidebarItems}
|
|
currentSlug={slug}
|
|
/>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Sidebar
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function LobSidebar({
|
|
items,
|
|
currentSlug,
|
|
}: {
|
|
items: LobSidebarItem[];
|
|
currentSlug: string;
|
|
}) {
|
|
// Split items into groups for visual sections
|
|
// Front matter: intro-segment items before chapters
|
|
// Texts: chapter items
|
|
// (LoB has no back matter)
|
|
|
|
const frontMatterItems: LobSidebarItem[] = [];
|
|
const textItems: LobSidebarItem[] = [];
|
|
|
|
for (const item of items) {
|
|
if (item.type === "chapter") {
|
|
textItems.push(item);
|
|
} else {
|
|
frontMatterItems.push(item);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<aside className="hidden lg:block w-56 shrink-0 sticky top-[89px] self-start max-h-[calc(100vh-89px)] overflow-y-auto py-8 pr-4">
|
|
{/* Front Matter */}
|
|
{frontMatterItems.length > 0 && (
|
|
<>
|
|
<h2 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-3 px-2">
|
|
Front Matter
|
|
</h2>
|
|
<nav className="flex flex-col gap-0.5 mb-4">
|
|
{frontMatterItems.map((item) => (
|
|
<SidebarLink
|
|
key={item.slug}
|
|
item={item}
|
|
isActive={item.slug === currentSlug}
|
|
/>
|
|
))}
|
|
</nav>
|
|
</>
|
|
)}
|
|
|
|
{/* Texts */}
|
|
{textItems.length > 0 && (
|
|
<>
|
|
<h2 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-3 px-2">
|
|
Texts
|
|
</h2>
|
|
<nav className="flex flex-col gap-0.5 mb-4">
|
|
{textItems.map((item) => (
|
|
<SidebarLink
|
|
key={item.slug}
|
|
item={item}
|
|
isActive={item.slug === currentSlug}
|
|
/>
|
|
))}
|
|
</nav>
|
|
</>
|
|
)}
|
|
</aside>
|
|
);
|
|
}
|
|
|
|
function SidebarLink({
|
|
item,
|
|
isActive,
|
|
}: {
|
|
item: LobSidebarItem;
|
|
isActive: boolean;
|
|
}) {
|
|
let label: string;
|
|
if (item.type === "chapter" && item.chapter != null) {
|
|
// Format: "N. Text N"
|
|
label = `${item.chapter}. Text ${item.chapter}`;
|
|
} else {
|
|
label = item.label;
|
|
}
|
|
|
|
return (
|
|
<Link
|
|
href={`/books/lob/${item.slug}`}
|
|
className={cn(
|
|
"px-2 py-1.5 rounded-md text-sm transition-colors truncate",
|
|
isActive
|
|
? "bg-primary/10 text-primary font-medium"
|
|
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
|
)}
|
|
title={label}
|
|
>
|
|
{label}
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Prev / Next navigation
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function LobNav({
|
|
prev,
|
|
next,
|
|
sidebarItems,
|
|
currentSlug,
|
|
}: {
|
|
prev: LobSidebarItem | null;
|
|
next: LobSidebarItem | null;
|
|
sidebarItems: LobSidebarItem[];
|
|
currentSlug: string;
|
|
}) {
|
|
const mobileNavGroups: MobileNavGroup[] = [];
|
|
|
|
const frontMatterItems: LobSidebarItem[] = [];
|
|
const textItems: LobSidebarItem[] = [];
|
|
|
|
for (const item of sidebarItems) {
|
|
if (item.type === "chapter") {
|
|
textItems.push(item);
|
|
} else {
|
|
frontMatterItems.push(item);
|
|
}
|
|
}
|
|
|
|
if (frontMatterItems.length > 0) {
|
|
mobileNavGroups.push({
|
|
title: "Front Matter",
|
|
items: frontMatterItems.map((i) => ({
|
|
slug: i.slug,
|
|
label: i.label,
|
|
href: `/books/lob/${i.slug}`,
|
|
type: i.type,
|
|
})),
|
|
});
|
|
}
|
|
|
|
if (textItems.length > 0) {
|
|
mobileNavGroups.push({
|
|
title: "Texts",
|
|
items: textItems.map((i) => ({
|
|
slug: i.slug,
|
|
label: i.label,
|
|
href: `/books/lob/${i.slug}`,
|
|
type: i.type,
|
|
})),
|
|
});
|
|
}
|
|
|
|
return (
|
|
<div className="flex items-center justify-between gap-3">
|
|
<div className="flex items-center gap-2">
|
|
<MobileNav
|
|
groups={mobileNavGroups}
|
|
currentSlug={currentSlug}
|
|
bookTitle="Light of the Bhāgavata"
|
|
/>
|
|
{prev ? (
|
|
<Link
|
|
href={`/books/lob/${prev.slug}`}
|
|
className={cn(
|
|
buttonVariants({ variant: "outline", size: "sm" }),
|
|
"gap-1.5",
|
|
)}
|
|
>
|
|
<ChevronLeft className="size-4" />
|
|
<span className="hidden sm:inline truncate max-w-[180px]">
|
|
{prev.type === "chapter" && prev.chapter != null
|
|
? `Text ${prev.chapter}`
|
|
: prev.label}
|
|
</span>
|
|
<span className="sm:hidden">Previous</span>
|
|
</Link>
|
|
) : (
|
|
<div className="hidden lg:block" />
|
|
)}
|
|
</div>
|
|
|
|
{next ? (
|
|
<Link
|
|
href={`/books/lob/${next.slug}`}
|
|
className={cn(
|
|
buttonVariants({ variant: "outline", size: "sm" }),
|
|
"gap-1.5",
|
|
)}
|
|
>
|
|
<span className="hidden sm:inline truncate max-w-[180px]">
|
|
{next.type === "chapter" && next.chapter != null
|
|
? `Text ${next.chapter}`
|
|
: next.label}
|
|
</span>
|
|
<span className="sm:hidden">Next</span>
|
|
<ChevronRight className="size-4" />
|
|
</Link>
|
|
) : (
|
|
<div />
|
|
)}
|
|
</div>
|
|
);
|
|
}
|