87 lines
2.8 KiB
TypeScript
87 lines
2.8 KiB
TypeScript
export const dynamic = "force-dynamic";
|
|
|
|
import type { Metadata } from "next";
|
|
import { redirect } from "next/navigation";
|
|
import { notFound } from "next/navigation";
|
|
import Link from "next/link";
|
|
import { getChapterVerseIndex, getProseChapter } from "@/lib/api";
|
|
import { buildOgMeta } from "@/lib/og";
|
|
import { BOOK_NAMES } from "@/lib/constants";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { PageHeader } from "@/components/layout/page-header";
|
|
import { FindInPage } from "@/components/layout/find-in-page";
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: {
|
|
params: Promise<{ chapter: string }>;
|
|
}): Promise<Metadata> {
|
|
const { chapter } = await params;
|
|
// Non-numeric segments are front matter (dedication, foreword, …).
|
|
if (isNaN(parseInt(chapter))) {
|
|
const segment = await getProseChapter("bg", 0, chapter);
|
|
return buildOgMeta({
|
|
title: BOOK_NAMES["bg"],
|
|
detail: segment?.title ?? "Front Matter",
|
|
});
|
|
}
|
|
return buildOgMeta({ title: BOOK_NAMES["bg"], detail: `Chapter ${chapter}` });
|
|
}
|
|
|
|
export default async function ChapterPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ chapter: string }>;
|
|
}) {
|
|
const { chapter } = await params;
|
|
|
|
// Front matter — non-numeric slugs (dedication, foreword, preface,
|
|
// introduction, disciplic-succession) resolve to prose intro-segments.
|
|
if (isNaN(parseInt(chapter))) {
|
|
const segment = await getProseChapter("bg", 0, chapter);
|
|
if (!segment) notFound();
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<PageHeader sticky>
|
|
<Link
|
|
href="/books/bg"
|
|
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
|
|
>
|
|
← {BOOK_NAMES["bg"]}
|
|
</Link>
|
|
<div className="mt-3 flex items-start justify-between gap-3">
|
|
<h1 className="text-2xl font-bold text-foreground">
|
|
{segment.title}
|
|
</h1>
|
|
<FindInPage targetId="book-content" className="shrink-0 mt-0.5" />
|
|
</div>
|
|
</PageHeader>
|
|
|
|
<main className="max-w-5xl mx-auto px-6 py-8">
|
|
<Card id="book-content">
|
|
<CardContent className="py-8 px-6 sm:px-8">
|
|
<div className="space-y-4">
|
|
{segment.paragraphs.map((paragraph, i) => (
|
|
<div
|
|
key={i}
|
|
className="text-base text-foreground leading-relaxed"
|
|
dangerouslySetInnerHTML={{ __html: paragraph }}
|
|
/>
|
|
))}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Numeric chapters — redirect to the first verse.
|
|
const verseIndex = await getChapterVerseIndex("bg", null, parseInt(chapter));
|
|
if (verseIndex.length === 0) {
|
|
notFound();
|
|
}
|
|
redirect(`/books/bg/${chapter}/${verseIndex[0].verse}`);
|
|
}
|