import Link from "next/link"; import { PageHeader } from "@/components/page-header"; import { Card, CardHeader, CardTitle, CardDescription, CardContent, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/utils"; import { ExtractedVerseCount } from "./extracted-verse-count"; import { getAllBooks, type BookMeta } from "@/lib/api"; type ChapterEntry = { totalVerses: number }; type CantoEntry = { totalChapters: number; chapters: ChapterEntry[] }; type LilaEntry = { totalChapters: number; chapters: ChapterEntry[] }; interface ChapterBookMeta extends BookMeta { totalChapters: number; chapters: ChapterEntry[]; } interface KbMeta extends BookMeta { totalChapters: number; description: string; volumes: { number: number; totalChapters: number }[]; } interface SbMeta extends BookMeta { totalCantos: number; cantos: CantoEntry[]; } interface CcMeta extends BookMeta { totalLilas: number; lilas: LilaEntry[]; } type BookInfo = { slug: string; title: string; author: string; description: string; totalVerses: number; href: string; }; function buildBookList(allBooks: BookMeta[]): BookInfo[] { const books: BookInfo[] = []; for (const data of allBooks) { const slug = data.book; const title = data.title as string; const author = data.author as string; if (slug === "bg") { const bg = data as ChapterBookMeta; const totalVerses = bg.chapters.reduce( (sum, ch) => sum + ch.totalVerses, 0, ); books.push({ slug, title, author, description: `${bg.totalChapters} chapters`, totalVerses, href: "/books/bg", }); } else if (slug === "sb1962") { const sb62 = data as ChapterBookMeta; const totalVerses = sb62.chapters.reduce( (sum, ch) => sum + ch.totalVerses, 0, ); books.push({ slug, title, author, description: `${sb62.totalChapters} chapters · First Canto`, totalVerses, href: "/books/sb1962", }); } else if (slug === "sb") { const sb = data as SbMeta; const totalChapters = sb.cantos.reduce( (sum, c) => sum + c.totalChapters, 0, ); const totalVerses = sb.cantos.reduce( (sum, c) => sum + c.chapters.reduce((s, ch) => s + ch.totalVerses, 0), 0, ); books.push({ slug, title, author, description: `${sb.totalCantos} cantos, ${totalChapters} chapters`, totalVerses, href: "/books/sb", }); } else if (slug === "cc") { const cc = data as CcMeta; const totalChapters = cc.lilas.reduce( (sum, l) => sum + l.totalChapters, 0, ); const totalVerses = cc.lilas.reduce( (sum, l) => sum + l.chapters.reduce((s, ch) => s + ch.totalVerses, 0), 0, ); books.push({ slug, title, author, description: `${cc.totalLilas} līlās, ${totalChapters} chapters`, totalVerses, href: "/books/cc", }); } else if (slug === "kb") { const kb = data as KbMeta; books.push({ slug, title, author, description: `${kb.totalChapters} chapters · 2 volumes`, totalVerses: 0, href: "/books/kb", }); } } return books; } export default async function BooksPage() { const allBooks = await getAllBooks(); const books = buildBookList(allBooks); return (
Structured verse-by-verse editions with Devanagari, transliteration, synonyms, translation & purports