175 lines
5.4 KiB
TypeScript
175 lines
5.4 KiB
TypeScript
import type { Metadata } from "next";
|
|
import Link from "next/link";
|
|
import { PageHeader } from "@/components/page-header";
|
|
import { getAllBooks, type BookMeta } from "@/lib/api";
|
|
import { buildOgMeta } from "@/lib/og";
|
|
import { BooksGrid, type BookInfo } from "./books-grid";
|
|
|
|
export function generateMetadata(): Metadata {
|
|
return buildOgMeta({
|
|
title: "Books",
|
|
detail: "Books by Śrīla Prabhupāda",
|
|
quote:
|
|
"Bhagavad-gītā, Śrīmad-Bhāgavatam, Caitanya-caritāmṛta, and 30+ other books with Devanagari, transliteration, synonyms, translations & purports.",
|
|
});
|
|
}
|
|
|
|
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 (
|
|
<div className="min-h-screen bg-background">
|
|
<PageHeader>
|
|
<Link
|
|
href="/"
|
|
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
|
|
>
|
|
← Home
|
|
</Link>
|
|
<h1 className="mt-3 text-3xl font-bold text-foreground">Books</h1>
|
|
<p className="mt-1 text-muted-foreground">
|
|
Browse the books and teachings of Śrīla Prabhupāda
|
|
</p>
|
|
</PageHeader>
|
|
|
|
<main className="max-w-5xl mx-auto px-6 py-8">
|
|
<BooksGrid books={books} />
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|