import fs from "fs"; import path from "path"; import Link from "next/link"; import { notFound } from "next/navigation"; import { VerseIndex } from "./verse-index"; type Synonym = { word: string; meanings: string[]; }; type Verse = { chapter: number; verse: number; reference: string; devanagari: string; transliteration: string; synonyms: Synonym[]; translation: string; purport: string[]; }; function getChapterVerses(chapter: string): Verse[] { const dir = path.join( process.cwd(), "app/lib/books/bg/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 getChapterTitle(chapter: string): string | null { const introPath = path.join( process.cwd(), "app/lib/books/bg/intro.json" ); const intro = JSON.parse(fs.readFileSync(introPath, "utf-8")); const ch = intro.chapters.find( (c: { number: number }) => c.number === parseInt(chapter) ); return ch?.title || null; } export default async function ChapterPage({ params, }: { params: Promise<{ chapter: string }>; }) { const { chapter } = await params; const title = getChapterTitle(chapter); if (!title) notFound(); const verses = getChapterVerses(chapter); if (verses.length === 0) notFound(); const verseList = verses.map((v) => ({ verse: v.verse, reference: v.reference, })); return (
← Bhagavad-gītā

Chapter {chapter}: {title}

{/* Left sidebar — verse index */} {/* Main content */}
{verses.map((verse) => (
{/* Header */}
{verse.reference}
{/* Devanagari */}

{verse.devanagari}

{/* Transliteration */}

{verse.transliteration}

{/* Synonyms */} {verse.synonyms.length > 0 && (

Synonyms

{verse.synonyms.map((s, i) => ( {s.word} —{s.meanings.join(", ")} {i < verse.synonyms.length - 1 ? "; " : "."} ))}

)} {/* Translation */}

Translation

{/* Purport */} {verse.purport.length > 0 && (

Purport

{verse.purport.map((p, i) => (

))}

)}
))}
); }