96 lines
3.0 KiB
TypeScript
96 lines
3.0 KiB
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
import Link from "next/link";
|
|
import { notFound } from "next/navigation";
|
|
import { ExtractedVerseCount } from "../../extracted-verse-count";
|
|
|
|
type ChapterInfo = {
|
|
number: number;
|
|
title: string;
|
|
totalVerses: number;
|
|
};
|
|
|
|
type CantoInfo = {
|
|
number: number;
|
|
title: string;
|
|
totalChapters: number;
|
|
chapters: ChapterInfo[];
|
|
};
|
|
|
|
type Intro = {
|
|
book: string;
|
|
title: string;
|
|
author: string;
|
|
totalCantos: number;
|
|
cantos: CantoInfo[];
|
|
};
|
|
|
|
function getIntro(): Intro {
|
|
const introPath = path.join(process.cwd(), "app/lib/books/sb/intro.json");
|
|
return JSON.parse(fs.readFileSync(introPath, "utf-8"));
|
|
}
|
|
|
|
export default async function CantoPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ canto: string }>;
|
|
}) {
|
|
const { canto } = await params;
|
|
const cantoNum = parseInt(canto);
|
|
const intro = getIntro();
|
|
|
|
const cantoInfo = intro.cantos.find((c) => c.number === cantoNum);
|
|
if (!cantoInfo) notFound();
|
|
|
|
const totalVerses = cantoInfo.chapters.reduce(
|
|
(sum, ch) => sum + ch.totalVerses,
|
|
0,
|
|
);
|
|
|
|
return (
|
|
<div className="min-h-screen bg-amber-50 dark:bg-zinc-950">
|
|
<header className="border-b border-amber-200 dark:border-zinc-800 bg-white dark:bg-zinc-900 px-6 py-8">
|
|
<div className="max-w-3xl mx-auto">
|
|
<Link
|
|
href="/books/sb"
|
|
className="text-sm text-amber-600 hover:text-amber-800 dark:text-zinc-400 dark:hover:text-zinc-100"
|
|
>
|
|
← Śrīmad-Bhāgavatam
|
|
</Link>
|
|
<h1 className="mt-3 text-3xl font-bold text-zinc-900 dark:text-zinc-100">
|
|
Canto {cantoInfo.number}: {cantoInfo.title}
|
|
</h1>
|
|
<p className="mt-1 text-zinc-500 dark:text-zinc-400">
|
|
{cantoInfo.totalChapters} chapters ·{" "}
|
|
<ExtractedVerseCount count={totalVerses} label="extracted verses" />
|
|
</p>
|
|
</div>
|
|
</header>
|
|
<main className="max-w-3xl mx-auto px-6 py-8">
|
|
<ul className="divide-y divide-amber-200 dark:divide-zinc-800 bg-white dark:bg-zinc-900 rounded-lg border border-amber-200 dark:border-zinc-800 overflow-hidden">
|
|
{cantoInfo.chapters.map((ch) => (
|
|
<li key={ch.number}>
|
|
<Link
|
|
href={`/books/sb/${cantoNum}/${ch.number}`}
|
|
className="flex items-center justify-between px-5 py-4 hover:bg-amber-50 dark:hover:bg-zinc-800 transition-colors"
|
|
>
|
|
<div>
|
|
<span className="text-sm text-amber-600 dark:text-amber-500 font-medium">
|
|
Chapter {ch.number}
|
|
</span>
|
|
<p className="font-medium text-zinc-900 dark:text-zinc-100">
|
|
{ch.title}
|
|
</p>
|
|
</div>
|
|
<span className="text-sm text-zinc-400 shrink-0 ml-4">
|
|
<ExtractedVerseCount count={ch.totalVerses} />
|
|
</span>
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|