feat: extract CC

This commit is contained in:
gosangam
2026-04-14 16:45:55 +05:30
parent c5d4194d00
commit e2f8063d90
11358 changed files with 850485 additions and 23197 deletions
+215
View File
@@ -0,0 +1,215 @@
import fs from "fs";
import path from "path";
import Link from "next/link";
import { PageHeader } from "@/components/page-header";
import { notFound } from "next/navigation";
import { Card, CardHeader, CardContent } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { VerseIndex } from "./verse-index";
type Synonym = {
word: string;
meanings: string[];
};
type Verse = {
book_title: string;
lila: string;
chapter: number;
verse: number;
verse_end?: number | null;
reference: string;
devanagari: string;
bengali: string;
transliteration: string;
synonyms: Synonym[];
translation: string;
purport: string[];
};
type ChapterInfo = {
number: number;
title: string;
totalVerses: number;
};
type LilaInfo = {
key: string;
name: string;
totalChapters: number;
totalVerses: number;
chapters: ChapterInfo[];
};
type Intro = {
book: string;
title: string;
author: string;
totalLilas: number;
lilas: LilaInfo[];
};
function getChapterVerses(lila: string, chapter: string): Verse[] {
const dir = path.join(
process.cwd(),
"app/lib/books/cc/lilas",
lila,
"chapters",
chapter.padStart(2, "0"),
"verses",
);
if (!fs.existsSync(dir)) return [];
return fs
.readdirSync(dir)
.filter((f) => f.endsWith(".json"))
.sort((a, b) => {
const na = parseInt(a);
const nb = parseInt(b);
return na - nb;
})
.map((f) => JSON.parse(fs.readFileSync(path.join(dir, f), "utf-8")));
}
function getLilaAndChapterInfo(
lila: string,
chapter: string,
): { lilaInfo: LilaInfo; chapterInfo: ChapterInfo } | null {
const introPath = path.join(process.cwd(), "app/lib/books/cc/intro.json");
const intro: Intro = JSON.parse(fs.readFileSync(introPath, "utf-8"));
const lilaInfo = intro.lilas.find((l) => l.key === lila);
if (!lilaInfo) return null;
const chapterInfo = lilaInfo.chapters.find(
(ch) => ch.number === parseInt(chapter),
);
if (!chapterInfo) return null;
return { lilaInfo, chapterInfo };
}
export default async function CcChapterPage({
params,
}: {
params: Promise<{ lila: string; chapter: string }>;
}) {
const { lila, chapter } = await params;
const info = getLilaAndChapterInfo(lila, chapter);
if (!info) notFound();
const { lilaInfo, chapterInfo } = info;
const verses = getChapterVerses(lila, chapter);
if (verses.length === 0) notFound();
const verseList = verses.map((v) => ({
verse: v.verse,
verse_end: v.verse_end ?? undefined,
reference: v.reference,
}));
return (
<div className="min-h-screen bg-background">
<PageHeader sticky wide>
<Link
href={`/books/cc/${lila}`}
className="text-sm text-muted-foreground hover:text-foreground"
>
&larr; {lilaInfo.name}
</Link>
<h1 className="mt-2 text-2xl font-bold text-foreground">
Chapter {chapter}: {chapterInfo.title}
</h1>
</PageHeader>
<div className="w-full md:max-w-5xl mx-auto flex">
{/* Left sidebar — verse index */}
<VerseIndex verses={verseList} chapter={chapter} />
{/* Main content */}
<main className="flex-1 min-w-0 px-6 py-8 space-y-12">
{verses.map((verse) => (
<Card
key={verse.reference}
id={`verse-${verse.verse}`}
className="scroll-mt-24"
>
{/* Header */}
<CardHeader className="border-b border-border bg-muted/50 py-3">
<Badge variant="secondary">{verse.reference}</Badge>
</CardHeader>
<CardContent className="space-y-5 pt-5">
{/* Bengali */}
{verse.bengali && (
<div className="text-center">
<p className="text-xl leading-relaxed whitespace-pre-line font-serif text-green-800 dark:text-green-400">
{verse.bengali}
</p>
</div>
)}
{/* Devanagari */}
<div className="text-center">
<p className="text-xl leading-relaxed text-red-800 dark:text-red-400 whitespace-pre-line font-serif">
{verse.devanagari}
</p>
</div>
{/* Transliteration */}
<div className="text-center">
<p className="text-base italic text-muted-foreground whitespace-pre-line">
{verse.transliteration}
</p>
</div>
{/* Synonyms */}
{verse.synonyms.length > 0 && (
<div>
<h3 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-2">
Synonyms
</h3>
<p className="text-sm text-muted-foreground leading-relaxed">
{verse.synonyms.map((s, i) => (
<span key={i}>
<span className="italic text-foreground">
{s.word}
</span>
—{s.meanings.join(", ")}
{i < verse.synonyms.length - 1 ? "; " : "."}
</span>
))}
</p>
</div>
)}
{/* Translation */}
<div>
<h3 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-2">
Translation
</h3>
<p
className="text-base text-foreground leading-relaxed font-medium"
dangerouslySetInnerHTML={{ __html: verse.translation }}
/>
</div>
{/* Purport */}
{verse.purport.length > 0 && (
<div>
<h3 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-2">
Purport
</h3>
<div className="text-sm text-muted-foreground leading-relaxed space-y-3">
{verse.purport.map((p, i) => (
<p key={i} dangerouslySetInnerHTML={{ __html: p }} />
))}
</div>
</div>
)}
</CardContent>
</Card>
))}
</main>
</div>
</div>
);
}
@@ -0,0 +1,62 @@
"use client";
import { useEffect, useState } from "react";
type VerseEntry = {
verse: number;
verse_end?: number;
reference: string;
};
export function VerseIndex({
verses,
chapter,
}: {
verses: VerseEntry[];
chapter: string;
}) {
const [activeVerse, setActiveVerse] = useState<number | null>(null);
useEffect(() => {
const observer = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
if (entry.isIntersecting) {
const id = entry.target.id;
const num = parseInt(id.replace("verse-", ""));
if (!isNaN(num)) setActiveVerse(num);
}
}
},
{ rootMargin: "-20% 0px -60% 0px" },
);
const articles = document.querySelectorAll("article[id^='verse-']");
articles.forEach((el) => observer.observe(el));
return () => observer.disconnect();
}, []);
return (
<aside className="hidden lg:block w-48 shrink-0 sticky top-[89px] self-start max-h-[calc(100vh-89px)] overflow-y-auto py-8 pr-4">
<h2 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-3 px-2">
Verses
</h2>
<nav className="grid grid-cols-3 gap-0.5">
{verses.map((v) => (
<a
key={v.verse}
href={`#verse-${v.verse}`}
className={`px-2 py-1 rounded-md text-sm text-center transition-colors ${
activeVerse === v.verse
? "bg-primary/10 text-primary font-medium"
: "text-muted-foreground hover:bg-muted hover:text-foreground"
}`}
>
{v.verse_end ? `${v.verse}–${v.verse_end}` : v.verse}
</a>
))}
</nav>
</aside>
);
}
+97
View File
@@ -0,0 +1,97 @@
import fs from "fs";
import path from "path";
import Link from "next/link";
import { PageHeader } from "@/components/page-header";
import { notFound } from "next/navigation";
import { Card, CardContent } from "@/components/ui/card";
import { ExtractedVerseCount } from "../../extracted-verse-count";
type ChapterInfo = {
number: number;
title: string;
totalVerses: number;
};
type LilaInfo = {
key: string;
name: string;
totalChapters: number;
totalVerses: number;
chapters: ChapterInfo[];
};
type Intro = {
book: string;
title: string;
author: string;
totalLilas: number;
lilas: LilaInfo[];
};
function getIntro(): Intro {
const introPath = path.join(process.cwd(), "app/lib/books/cc/intro.json");
return JSON.parse(fs.readFileSync(introPath, "utf-8"));
}
export default async function LilaPage({
params,
}: {
params: Promise<{ lila: string }>;
}) {
const { lila } = await params;
const intro = getIntro();
const lilaInfo = intro.lilas.find((l) => l.key === lila);
if (!lilaInfo) notFound();
const totalVerses = lilaInfo.chapters.reduce(
(sum, ch) => sum + ch.totalVerses,
0,
);
return (
<div className="min-h-screen bg-background">
<PageHeader>
<Link
href="/books/cc"
className="text-sm text-muted-foreground hover:text-foreground"
>
&larr; Śrī Caitanya-caritāmṛta
</Link>
<h1 className="mt-3 text-3xl font-bold text-foreground">
{lilaInfo.name}
</h1>
<p className="mt-1 text-muted-foreground">
{lilaInfo.totalChapters} chapters ·{" "}
<ExtractedVerseCount count={totalVerses} label="extracted verses" />
</p>
</PageHeader>
<main className="max-w-3xl mx-auto px-6 py-8">
<Card className="divide-y divide-border">
<CardContent className="p-0">
<ul className="divide-y divide-border">
{lilaInfo.chapters.map((ch) => (
<li key={ch.number}>
<Link
href={`/books/cc/${lila}/${ch.number}`}
className="flex items-center justify-between px-5 py-4 hover:bg-muted transition-colors"
>
<div>
<span className="text-sm text-primary font-medium">
Chapter {ch.number}
</span>
<p className="font-medium text-foreground">{ch.title}</p>
</div>
<span className="text-sm text-muted-foreground shrink-0 ml-4">
<ExtractedVerseCount count={ch.totalVerses} />
</span>
</Link>
</li>
))}
</ul>
</CardContent>
</Card>
</main>
</div>
);
}
+88
View File
@@ -0,0 +1,88 @@
import fs from "fs";
import path from "path";
import Link from "next/link";
import { PageHeader } from "@/components/page-header";
import { Card, CardContent } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { ExtractedVerseCount } from "../extracted-verse-count";
type ChapterInfo = {
number: number;
title: string;
totalVerses: number;
};
type LilaInfo = {
key: string;
name: string;
totalChapters: number;
totalVerses: number;
chapters: ChapterInfo[];
};
type Intro = {
book: string;
title: string;
author: string;
totalLilas: number;
lilas: LilaInfo[];
};
export default function CcPage() {
const introPath = path.join(process.cwd(), "app/lib/books/cc/intro.json");
const intro: Intro = JSON.parse(fs.readFileSync(introPath, "utf-8"));
return (
<div className="min-h-screen bg-background">
<PageHeader>
<Link
href="/books"
className="text-sm text-muted-foreground hover:text-foreground"
>
&larr; Books
</Link>
<h1 className="mt-3 text-3xl font-bold text-foreground">
{intro.title}
</h1>
<p className="mt-1 text-muted-foreground">{intro.author}</p>
</PageHeader>
<main className="max-w-3xl mx-auto px-6 py-8">
<Card className="divide-y divide-border">
<CardContent className="p-0">
<ul className="divide-y divide-border">
{intro.lilas.map((lila) => {
const totalVerses = lila.chapters.reduce(
(sum, ch) => sum + ch.totalVerses,
0,
);
return (
<li key={lila.key}>
<Link
href={`/books/cc/${lila.key}`}
className="flex items-center justify-between px-5 py-4 hover:bg-muted transition-colors"
>
<div>
<Badge variant="secondary" className="mb-1">
{lila.name}
</Badge>
<p className="font-medium text-foreground">
{lila.totalChapters} chapters
</p>
</div>
<span className="text-sm text-muted-foreground shrink-0 ml-4">
<ExtractedVerseCount
count={totalVerses}
label="extracted verses"
/>
</span>
</Link>
</li>
);
})}
</ul>
</CardContent>
</Card>
</main>
</div>
);
}
+27
View File
@@ -71,6 +71,33 @@ function loadBooks(): BookInfo[] {
});
}
// Ś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",
});
}
return books;
}