mongo fix

This commit is contained in:
gosangam
2026-04-14 19:12:11 +05:30
parent e2f8063d90
commit beffb9fae1
172 changed files with 18029 additions and 1298 deletions
+79 -75
View File
@@ -1,5 +1,3 @@
import fs from "fs";
import path from "path";
import Link from "next/link";
import { PageHeader } from "@/components/page-header";
import {
@@ -12,6 +10,26 @@ import {
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 BgMeta extends BookMeta {
totalChapters: number;
chapters: ChapterEntry[];
}
interface SbMeta extends BookMeta {
totalCantos: number;
cantos: CantoEntry[];
}
interface CcMeta extends BookMeta {
totalLilas: number;
lilas: LilaEntry[];
}
type BookInfo = {
slug: string;
@@ -22,87 +40,73 @@ type BookInfo = {
href: string;
};
function loadBooks(): BookInfo[] {
const booksDir = path.join(process.cwd(), "app/lib/books");
function buildBookList(allBooks: BookMeta[]): BookInfo[] {
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",
});
}
for (const data of allBooks) {
const slug = data.book;
const title = data.title as string;
const author = data.author as string;
// Ś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",
});
}
// Śrī Caitanya-caritāmṛta
const ccIntroPath = path.join(booksDir, "cc", "intro.json");
if (fs.existsSync(ccIntroPath)) {
const cc = JSON.parse(fs.readFileSync(ccIntroPath, "utf-8"));
const totalChapters = cc.lilas.reduce(
(sum: number, l: { totalChapters: number }) => sum + l.totalChapters,
0,
);
const totalVerses = cc.lilas.reduce(
(sum: number, l: { chapters: { totalVerses: number }[] }) =>
sum +
l.chapters.reduce(
(s: number, ch: { totalVerses: number }) => s + ch.totalVerses,
0,
),
0,
);
books.push({
slug: "cc",
title: cc.title,
author: cc.author,
description: `${cc.totalLilas} līlās, ${totalChapters} chapters`,
totalVerses,
href: "/books/cc",
});
if (slug === "bg") {
const bg = data as BgMeta;
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 === "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",
});
}
}
return books;
}
export default function BooksPage() {
const books = loadBooks();
export default async function BooksPage() {
const allBooks = await getAllBooks();
const books = buildBookList(allBooks);
return (
<div className="min-h-screen bg-background">