346 lines
10 KiB
TypeScript
346 lines
10 KiB
TypeScript
import Link from "next/link";
|
|
import { notFound } from "next/navigation";
|
|
import {
|
|
getNoiContent,
|
|
getNoiSidebarItems,
|
|
type NoiVerse,
|
|
type NoiIntroSegment,
|
|
type NoiSidebarItem,
|
|
} from "@/lib/noi";
|
|
import { PageHeader } from "@/components/page-header";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { buttonVariants } from "@/components/ui/button";
|
|
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Type guards
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function isVerse(content: NoiVerse | NoiIntroSegment): content is NoiVerse {
|
|
return "text" in content && "devanagari" in content;
|
|
}
|
|
|
|
function isIntroSegment(
|
|
content: NoiVerse | NoiIntroSegment,
|
|
): content is NoiIntroSegment {
|
|
return "paragraphs" in content && "order" in content;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Page
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export default async function NoiTextPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ text: string }>;
|
|
}) {
|
|
const { text: slug } = await params;
|
|
|
|
const content = await getNoiContent(slug);
|
|
if (!content) notFound();
|
|
|
|
const sidebarItems = await getNoiSidebarItems();
|
|
const currentIdx = sidebarItems.findIndex((item) => item.slug === slug);
|
|
|
|
const prev = currentIdx > 0 ? sidebarItems[currentIdx - 1] : null;
|
|
const next =
|
|
currentIdx < sidebarItems.length - 1 ? sidebarItems[currentIdx + 1] : null;
|
|
|
|
// Build the page title for the header
|
|
const verse = isVerse(content) ? content : null;
|
|
const intro = isIntroSegment(content) ? content : null;
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<PageHeader sticky wide>
|
|
<Link
|
|
href="/books/noi"
|
|
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
|
|
>
|
|
← The Nectar of Instruction
|
|
</Link>
|
|
<h1 className="mt-3 text-2xl font-bold text-foreground">
|
|
{verse && (
|
|
<>
|
|
<span className="text-primary">Text {verse.text}: </span>
|
|
{verse.title}
|
|
</>
|
|
)}
|
|
{intro && intro.title}
|
|
</h1>
|
|
</PageHeader>
|
|
|
|
<div className="w-full md:max-w-6xl mx-auto flex">
|
|
{/* Left sidebar */}
|
|
<NoiSidebar items={sidebarItems} currentSlug={slug} />
|
|
|
|
{/* Main content */}
|
|
<main className="flex-1 min-w-0 px-6 py-8 space-y-8">
|
|
{/* Top navigation */}
|
|
<NoiNav prev={prev} next={next} />
|
|
|
|
{/* Content */}
|
|
{verse && <VerseContent verse={verse} />}
|
|
{intro && <IntroContent intro={intro} />}
|
|
|
|
{/* Bottom navigation */}
|
|
<NoiNav prev={prev} next={next} />
|
|
</main>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Verse content (Devanagari, transliteration, synonyms, translation, purport)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function VerseContent({ verse }: { verse: NoiVerse }) {
|
|
return (
|
|
<Card>
|
|
<CardContent className="py-8 px-6 sm:px-8 space-y-8">
|
|
{/* Devanagari */}
|
|
<section>
|
|
<div className="text-xl leading-relaxed text-foreground whitespace-pre-line font-serif text-center">
|
|
{verse.devanagari}
|
|
</div>
|
|
</section>
|
|
|
|
{/* Transliteration */}
|
|
<section>
|
|
<div className="text-foreground/80 italic whitespace-pre-line leading-relaxed text-center">
|
|
{verse.transliteration}
|
|
</div>
|
|
</section>
|
|
|
|
{/* Synonyms */}
|
|
{verse.synonyms.length > 0 && (
|
|
<section>
|
|
<h2 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-3">
|
|
Synonyms
|
|
</h2>
|
|
<div className="text-sm text-foreground/70 leading-relaxed">
|
|
{verse.synonyms.map((s, i) => (
|
|
<span key={i}>
|
|
{i > 0 && "; "}
|
|
<span className="font-medium text-foreground/90">
|
|
{s.word}
|
|
</span>
|
|
{"—"}
|
|
{s.meanings.join(", ")}
|
|
</span>
|
|
))}
|
|
</div>
|
|
</section>
|
|
)}
|
|
|
|
{/* Translation */}
|
|
<section>
|
|
<h2 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-3">
|
|
Translation
|
|
</h2>
|
|
<div
|
|
className="text-foreground font-medium leading-relaxed"
|
|
dangerouslySetInnerHTML={{ __html: verse.translation }}
|
|
/>
|
|
</section>
|
|
|
|
{/* Purport */}
|
|
{verse.purport.length > 0 && (
|
|
<section>
|
|
<h2 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-3">
|
|
Purport
|
|
</h2>
|
|
<div className="space-y-4">
|
|
{verse.purport.map((p, i) => (
|
|
<div
|
|
key={i}
|
|
className="text-foreground leading-relaxed"
|
|
dangerouslySetInnerHTML={{ __html: p }}
|
|
/>
|
|
))}
|
|
</div>
|
|
</section>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Intro segment content (paragraphs)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function IntroContent({ intro }: { intro: NoiIntroSegment }) {
|
|
return (
|
|
<Card>
|
|
<CardContent className="py-8 px-6 sm:px-8">
|
|
<div className="space-y-4">
|
|
{intro.paragraphs.map((paragraph, i) => (
|
|
<div
|
|
key={i}
|
|
className="text-foreground leading-relaxed"
|
|
dangerouslySetInnerHTML={{ __html: paragraph }}
|
|
/>
|
|
))}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Sidebar
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function NoiSidebar({
|
|
items,
|
|
currentSlug,
|
|
}: {
|
|
items: NoiSidebarItem[];
|
|
currentSlug: string;
|
|
}) {
|
|
// Front matter items (front-pages + preface)
|
|
const frontMatterItems = items.filter(
|
|
(item) =>
|
|
item.slug === "intro-front-pages" || item.slug === "intro-preface",
|
|
);
|
|
// Texts = 1-11
|
|
const textItems = items.filter((item) => item.type === "verse");
|
|
// Appendixes comes last
|
|
const appendixesItem = items.find(
|
|
(item) => item.slug === "intro-appendixes",
|
|
);
|
|
|
|
return (
|
|
<aside className="hidden lg:block w-56 shrink-0 sticky top-[89px] self-start max-h-[calc(100vh-89px)] overflow-y-auto py-8 pr-4">
|
|
{/* Front Matter */}
|
|
{frontMatterItems.length > 0 && (
|
|
<>
|
|
<h2 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-3 px-2">
|
|
Front Matter
|
|
</h2>
|
|
<nav className="flex flex-col gap-0.5 mb-4">
|
|
{frontMatterItems.map((item) => (
|
|
<SidebarLink
|
|
key={item.slug}
|
|
item={item}
|
|
isActive={item.slug === currentSlug}
|
|
/>
|
|
))}
|
|
</nav>
|
|
</>
|
|
)}
|
|
|
|
{/* Texts */}
|
|
{textItems.length > 0 && (
|
|
<>
|
|
<h2 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-3 px-2">
|
|
Texts
|
|
</h2>
|
|
<nav className="flex flex-col gap-0.5 mb-4">
|
|
{textItems.map((item) => (
|
|
<SidebarLink
|
|
key={item.slug}
|
|
item={item}
|
|
isActive={item.slug === currentSlug}
|
|
/>
|
|
))}
|
|
</nav>
|
|
</>
|
|
)}
|
|
|
|
{/* Appendixes */}
|
|
{appendixesItem && (
|
|
<nav className="flex flex-col gap-0.5">
|
|
<SidebarLink
|
|
item={appendixesItem}
|
|
isActive={appendixesItem.slug === currentSlug}
|
|
/>
|
|
</nav>
|
|
)}
|
|
</aside>
|
|
);
|
|
}
|
|
|
|
function SidebarLink({
|
|
item,
|
|
isActive,
|
|
}: {
|
|
item: NoiSidebarItem;
|
|
isActive: boolean;
|
|
}) {
|
|
return (
|
|
<Link
|
|
href={`/books/noi/${item.slug}`}
|
|
className={cn(
|
|
"px-2 py-1.5 rounded-md text-sm transition-colors truncate",
|
|
isActive
|
|
? "bg-primary/10 text-primary font-medium"
|
|
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
|
)}
|
|
title={item.label}
|
|
>
|
|
{item.label}
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Prev / Next navigation
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function NoiNav({
|
|
prev,
|
|
next,
|
|
}: {
|
|
prev: NoiSidebarItem | null;
|
|
next: NoiSidebarItem | null;
|
|
}) {
|
|
return (
|
|
<div className="flex items-center justify-between gap-3">
|
|
{prev ? (
|
|
<Link
|
|
href={`/books/noi/${prev.slug}`}
|
|
className={cn(
|
|
buttonVariants({ variant: "outline", size: "sm" }),
|
|
"gap-1.5",
|
|
)}
|
|
>
|
|
<ChevronLeft className="size-4" />
|
|
<span className="hidden sm:inline truncate max-w-[180px]">
|
|
{prev.type === "verse" && prev.text != null
|
|
? `Text ${prev.text}`
|
|
: prev.label}
|
|
</span>
|
|
<span className="sm:hidden">Previous</span>
|
|
</Link>
|
|
) : (
|
|
<div />
|
|
)}
|
|
|
|
{next ? (
|
|
<Link
|
|
href={`/books/noi/${next.slug}`}
|
|
className={cn(
|
|
buttonVariants({ variant: "outline", size: "sm" }),
|
|
"gap-1.5",
|
|
)}
|
|
>
|
|
<span className="hidden sm:inline truncate max-w-[180px]">
|
|
{next.type === "verse" && next.text != null
|
|
? `Text ${next.text}`
|
|
: next.label}
|
|
</span>
|
|
<span className="sm:hidden">Next</span>
|
|
<ChevronRight className="size-4" />
|
|
</Link>
|
|
) : (
|
|
<div />
|
|
)}
|
|
</div>
|
|
);
|
|
}
|