import fs from "fs"; import path from "path"; import Link from "next/link"; import { ExtractedVerseCount } from "./extracted-verse-count"; type BookInfo = { slug: string; title: string; author: string; description: string; totalVerses: number; href: string; }; function loadBooks(): BookInfo[] { const booksDir = path.join(process.cwd(), "app/lib/books"); const books: BookInfo[] = []; // Bhagavad-gītā const bgIntroPath = path.join(booksDir, "bg", "intro.json"); if (fs.existsSync(bgIntroPath)) { const bg = JSON.parse(fs.readFileSync(bgIntroPath, "utf-8")); const totalVerses = bg.chapters.reduce( (sum: number, ch: { totalVerses: number }) => sum + ch.totalVerses, 0, ); books.push({ slug: "bg", title: bg.title, author: bg.author, description: `${bg.totalChapters} chapters`, totalVerses, href: "/books/bg", }); } // Śrīmad-Bhāgavatam const sbIntroPath = path.join(booksDir, "sb", "intro.json"); if (fs.existsSync(sbIntroPath)) { const sb = JSON.parse(fs.readFileSync(sbIntroPath, "utf-8")); const totalChapters = sb.cantos.reduce( (sum: number, c: { totalChapters: number }) => sum + c.totalChapters, 0, ); const totalVerses = sb.cantos.reduce( (sum: number, c: { chapters: { totalVerses: number }[] }) => sum + c.chapters.reduce( (s: number, ch: { totalVerses: number }) => s + ch.totalVerses, 0, ), 0, ); books.push({ slug: "sb", title: sb.title, author: sb.author, description: `${sb.totalCantos} cantos, ${totalChapters} chapters`, totalVerses, href: "/books/sb", }); } return books; } export default function BooksPage() { const books = loadBooks(); return (
← Home

Books

Structured verse-by-verse editions with Devanagari, transliteration, synonyms, translation & purports

{books.map((book) => (

{book.title}

{book.author}

{book.description}
))}
); }