import Link from "next/link"; import { PageHeader } from "@/components/page-header"; import { getAllBooks, type BookMeta } from "@/lib/api"; import { BooksGrid, type BookInfo } from "./books-grid"; 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 SbMeta extends BookMeta { totalCantos: number; cantos: CantoEntry[]; } interface CcMeta extends BookMeta { totalLilas: number; lilas: LilaEntry[]; } 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`, contentDescription: "The essence of Vedic knowledge — Lord Kṛṣṇa's teachings to Arjuna on the battlefield of Kurukṣetra.", 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`, contentDescription: (data as { description?: string }).description || "The original 1962 Indian edition of the 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`, contentDescription: "The ripened fruit of Vedic literature — the science of God in 18,000 verses.", 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`, contentDescription: "The life and teachings of Lord Caitanya Mahāprabhu — the most complete theistic science.", totalVerses, href: "/books/cc", }); } else { // Generic handler for all other books — pulls description from metadata const metaDesc = (data as { description?: string }).description || ""; const totalChapters = (data as { totalChapters?: number }).totalChapters; const totalMantras = (data as { totalMantras?: number }).totalMantras; const totalTexts = (data as { totalTexts?: number }).totalTexts; const parts = (data as { parts?: unknown[] }).parts; const volumes = (data as { volumes?: unknown[] }).volumes; let badge = ""; if (totalMantras) badge = `${totalMantras} mantras`; else if (totalTexts) badge = `${totalTexts} texts`; else if (totalChapters && volumes) badge = `${totalChapters} chapters · ${volumes.length} volumes`; else if (totalChapters && parts) badge = `${totalChapters} chapters · ${parts.length} parts`; else if (totalChapters) badge = `${totalChapters} chapters`; books.push({ slug, title, author, description: badge, contentDescription: metaDesc, totalVerses: 0, href: `/books/${slug}`, }); } } return books; } export default async function BooksPage() { const allBooks = await getAllBooks(); const books = buildBookList(allBooks); return (
← Home

Books

Browse the books and teachings of Śrīla Prabhupāda

); }