feat: letters added

This commit is contained in:
gosangam
2026-05-04 00:08:31 +05:30
parent 35d1d14f37
commit 401766928a
20 changed files with 4272 additions and 26 deletions
+117
View File
@@ -0,0 +1,117 @@
export const dynamic = "force-dynamic";
import Link from "next/link";
import { notFound } from "next/navigation";
import { getLetter, getAdjacentLetters } from "@/lib/letters";
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";
export default async function LetterPage({
params,
}: {
params: Promise<{ slug: string }>;
}) {
const { slug } = await params;
const letter = await getLetter(slug);
if (!letter) notFound();
const { prev, next } = await getAdjacentLetters(slug, letter.year);
const backHref = letter.year ? `/letters/year/${letter.year}` : "/letters";
const backLabel = letter.year ? `Letters from ${letter.year}` : "Letters";
return (
<div className="min-h-screen bg-background">
<PageHeader sticky>
<Link
href={backHref}
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
>
&larr; {backLabel}
</Link>
<h1 className="mt-3 text-2xl font-bold text-foreground">
Letter to {letter.recipientDisplay}
</h1>
<p className="mt-1 text-sm text-muted-foreground">
{letter.date}
{letter.location ? ` · ${letter.location}` : ""}
</p>
</PageHeader>
<main className="max-w-3xl mx-auto px-6 py-8 space-y-8">
{/* Top nav */}
<LetterNav prev={prev} next={next} />
{/* Letter content */}
<Card>
<CardContent className="py-8 px-6 sm:px-8">
<div className="space-y-4">
{letter.paragraphs.map((paragraph, i) => (
<div
key={i}
className="text-base text-foreground leading-relaxed"
dangerouslySetInnerHTML={{ __html: paragraph }}
/>
))}
</div>
</CardContent>
</Card>
{/* Bottom nav */}
<LetterNav prev={prev} next={next} />
</main>
</div>
);
}
function LetterNav({
prev,
next,
}: {
prev: { slug: string; recipientDisplay: string } | null;
next: { slug: string; recipientDisplay: string } | null;
}) {
return (
<div className="flex items-center justify-between gap-3">
{prev ? (
<Link
href={`/letters/${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.recipientDisplay}
</span>
<span className="sm:hidden">Previous</span>
</Link>
) : (
<div />
)}
{next ? (
<Link
href={`/letters/${next.slug}`}
className={cn(
buttonVariants({ variant: "outline", size: "sm" }),
"gap-1.5",
)}
>
<span className="hidden sm:inline truncate max-w-[180px]">
{next.recipientDisplay}
</span>
<span className="sm:hidden">Next</span>
<ChevronRight className="size-4" />
</Link>
) : (
<div />
)}
</div>
);
}
+285
View File
@@ -0,0 +1,285 @@
"use client";
import { useState, useMemo } from "react";
import Link from "next/link";
import {
Card,
CardContent,
} from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";
import { Search, ChevronLeft, ChevronRight } from "lucide-react";
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
export type YearGroup = { year: number; count: number };
export type RecipientGroup = { name: string; count: number };
export type LocationGroup = { name: string; count: number };
// ---------------------------------------------------------------------------
// Diacritic-aware normalize (matches books-grid pattern)
// ---------------------------------------------------------------------------
function normalize(text: string): string {
return text
.toLowerCase()
.replace(/ṛ/g, "r")
.replace(/ṝ/g, "r")
.replace(/ṣ/g, "s")
.replace(/ś/g, "s")
.replace(/ṭ/g, "t")
.replace(/ḍ/g, "d")
.replace(/ṇ/g, "n")
.replace(/ñ/g, "n")
.replace(/ṅ/g, "n")
.replace(/ḥ/g, "h")
.replace(/ṁ/g, "m")
.replace(/ṃ/g, "m")
.replace(/ḷ/g, "l")
.replace(/ā/g, "a")
.replace(/ī/g, "i")
.replace(/ū/g, "u")
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "");
}
// ---------------------------------------------------------------------------
// Pagination
// ---------------------------------------------------------------------------
const PAGE_SIZE_RECIPIENTS = 50;
const PAGE_SIZE_LOCATIONS = 60;
const PAGE_SIZE_YEARS = 100; // years are small cards, show all usually
function Pagination({
page,
totalPages,
onPageChange,
}: {
page: number;
totalPages: number;
onPageChange: (p: number) => void;
}) {
if (totalPages <= 1) return null;
return (
<div className="flex items-center justify-center gap-3 pt-4">
<button
onClick={() => onPageChange(page - 1)}
disabled={page <= 1}
className={cn(
"flex items-center gap-1 px-3 py-1.5 rounded-md text-sm font-medium transition-colors",
page <= 1
? "text-muted-foreground/40 cursor-not-allowed"
: "text-muted-foreground hover:bg-muted hover:text-foreground",
)}
>
<ChevronLeft className="size-4" />
Previous
</button>
<span className="text-sm text-muted-foreground">
Page {page} of {totalPages}
</span>
<button
onClick={() => onPageChange(page + 1)}
disabled={page >= totalPages}
className={cn(
"flex items-center gap-1 px-3 py-1.5 rounded-md text-sm font-medium transition-colors",
page >= totalPages
? "text-muted-foreground/40 cursor-not-allowed"
: "text-muted-foreground hover:bg-muted hover:text-foreground",
)}
>
Next
<ChevronRight className="size-4" />
</button>
</div>
);
}
// ---------------------------------------------------------------------------
// Component
// ---------------------------------------------------------------------------
export function LettersBrowser({
currentView,
years,
recipients,
locations,
}: {
currentView: string;
years: YearGroup[];
recipients: RecipientGroup[];
locations: LocationGroup[];
}) {
const [query, setQuery] = useState("");
const [page, setPage] = useState(1);
// Reset page when query or view changes
const handleQueryChange = (q: string) => {
setQuery(q);
setPage(1);
};
// --- Filtered data ---
const filteredYears = useMemo(() => {
if (!query.trim()) return years;
const q = normalize(query.trim());
return years.filter((yg) => String(yg.year).includes(q));
}, [years, query]);
const filteredRecipients = useMemo(() => {
if (!query.trim()) return recipients;
const q = normalize(query.trim());
return recipients.filter((rg) => normalize(rg.name).includes(q));
}, [recipients, query]);
const filteredLocations = useMemo(() => {
if (!query.trim()) return locations;
const q = normalize(query.trim());
return locations.filter((lg) => normalize(lg.name).includes(q));
}, [locations, query]);
// --- Paginated data ---
const activeData =
currentView === "year"
? filteredYears
: currentView === "recipient"
? filteredRecipients
: filteredLocations;
const pageSize =
currentView === "year"
? PAGE_SIZE_YEARS
: currentView === "recipient"
? PAGE_SIZE_RECIPIENTS
: PAGE_SIZE_LOCATIONS;
const totalPages = Math.max(1, Math.ceil(activeData.length / pageSize));
const safePage = Math.min(page, totalPages);
const startIdx = (safePage - 1) * pageSize;
const endIdx = startIdx + pageSize;
const placeholder =
currentView === "year"
? "Search years..."
: currentView === "recipient"
? "Search recipients..."
: "Search locations...";
const resultCount = activeData.length;
const totalCount =
currentView === "year"
? years.length
: currentView === "recipient"
? recipients.length
: locations.length;
return (
<div className="space-y-4">
{/* Search */}
<div className="relative">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" />
<Input
type="text"
placeholder={placeholder}
value={query}
onChange={(e) => handleQueryChange(e.target.value)}
className="pl-9"
/>
</div>
{/* Result count */}
{query.trim() && (
<p className="text-sm text-muted-foreground">
{resultCount === 0
? "No results found"
: `${resultCount} of ${totalCount} ${currentView === "year" ? "years" : currentView === "recipient" ? "recipients" : "locations"}`}
</p>
)}
{/* Year view */}
{currentView === "year" && (
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3">
{(filteredYears.slice(startIdx, endIdx) as YearGroup[]).map((yg) => (
<Link key={yg.year} href={`/letters/year/${yg.year}`}>
<Card className="transition-all hover:shadow-md hover:ring-foreground/20">
<CardContent className="py-4 px-4 text-center">
<p className="text-lg font-bold text-foreground">
{yg.year}
</p>
<p className="text-xs text-muted-foreground">
{yg.count} {yg.count === 1 ? "letter" : "letters"}
</p>
</CardContent>
</Card>
</Link>
))}
</div>
)}
{/* Recipient view */}
{currentView === "recipient" && (
<div className="space-y-1.5">
{(filteredRecipients.slice(startIdx, endIdx) as RecipientGroup[]).map(
(rg) => (
<Link
key={rg.name}
href={`/letters/recipient/${encodeURIComponent(rg.name)}`}
className="block"
>
<Card className="transition-all hover:shadow-md hover:ring-foreground/20">
<CardContent className="py-3 px-5 flex items-center justify-between">
<p className="font-medium text-foreground truncate">
{rg.name}
</p>
<Badge variant="secondary" className="text-xs shrink-0 ml-3">
{rg.count}
</Badge>
</CardContent>
</Card>
</Link>
),
)}
</div>
)}
{/* Location view */}
{currentView === "location" && (
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-3">
{(filteredLocations.slice(startIdx, endIdx) as LocationGroup[]).map(
(lg) => (
<Link
key={lg.name}
href={`/letters/location/${encodeURIComponent(lg.name)}`}
>
<Card className="transition-all hover:shadow-md hover:ring-foreground/20">
<CardContent className="py-4 px-4 text-center">
<p className="font-medium text-foreground">{lg.name}</p>
<p className="text-xs text-muted-foreground">
{lg.count} {lg.count === 1 ? "letter" : "letters"}
</p>
</CardContent>
</Card>
</Link>
),
)}
</div>
)}
{/* Pagination */}
<Pagination
page={safePage}
totalPages={totalPages}
onPageChange={setPage}
/>
</div>
);
}
+37
View File
@@ -0,0 +1,37 @@
"use client";
import Link from "next/link";
import { cn } from "@/lib/utils";
import { Calendar, User, MapPin } from "lucide-react";
const views = [
{ key: "year", label: "By Year", icon: Calendar },
{ key: "recipient", label: "By Recipient", icon: User },
{ key: "location", label: "By Location", icon: MapPin },
];
export function LettersNav({ currentView }: { currentView: string }) {
return (
<div className="flex gap-2 border-b border-border pb-3">
{views.map((v) => {
const Icon = v.icon;
const isActive = currentView === v.key;
return (
<Link
key={v.key}
href={`/letters?view=${v.key}`}
className={cn(
"flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors",
isActive
? "bg-primary/10 text-primary"
: "text-muted-foreground hover:bg-muted hover:text-foreground",
)}
>
<Icon className="size-4" />
{v.label}
</Link>
);
})}
</div>
);
}
+64
View File
@@ -0,0 +1,64 @@
export const dynamic = "force-dynamic";
import Link from "next/link";
import { notFound } from "next/navigation";
import { getLettersByLocation } from "@/lib/letters";
import { PageHeader } from "@/components/page-header";
import { Card, CardContent } from "@/components/ui/card";
export default async function LettersByLocationPage({
params,
}: {
params: Promise<{ name: string }>;
}) {
const { name: encodedName } = await params;
const name = decodeURIComponent(encodedName);
const letters = await getLettersByLocation(name);
if (letters.length === 0) notFound();
return (
<div className="min-h-screen bg-background">
<PageHeader>
<Link
href="/letters?view=location"
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
>
&larr; Letters by Location
</Link>
<h1 className="mt-3 text-3xl font-bold text-foreground">
Letters from {name}
</h1>
<p className="mt-1 text-muted-foreground">
{letters.length} {letters.length === 1 ? "letter" : "letters"}
</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">
{letters.map((letter) => (
<li key={letter.slug}>
<Link
href={`/letters/${letter.slug}`}
className="flex flex-col sm:flex-row sm:items-center sm:justify-between px-5 py-4 gap-1 sm:gap-4 hover:bg-muted transition-colors"
>
<div className="min-w-0">
<p className="font-medium text-foreground">
To: {letter.recipientDisplay}
</p>
<p className="text-sm text-muted-foreground">
{letter.date || "Undated"}
</p>
</div>
</Link>
</li>
))}
</ul>
</CardContent>
</Card>
</main>
</div>
);
}
+55
View File
@@ -0,0 +1,55 @@
export const dynamic = "force-dynamic";
import Link from "next/link";
import { PageHeader } from "@/components/page-header";
import {
getLetterYears,
getLetterRecipients,
getLetterLocations,
getTotalLetterCount,
} from "@/lib/letters";
import { LettersNav } from "./letters-nav";
import { LettersBrowser } from "./letters-browser";
export default async function LettersPage({
searchParams,
}: {
searchParams: Promise<{ view?: string }>;
}) {
const { view = "year" } = await searchParams;
const [years, recipients, locations, totalCount] = await Promise.all([
getLetterYears(),
getLetterRecipients(),
getLetterLocations(),
getTotalLetterCount(),
]);
return (
<div className="min-h-screen bg-background">
<PageHeader>
<Link
href="/"
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
>
&larr; Home
</Link>
<h1 className="mt-3 text-3xl font-bold text-foreground">Letters</h1>
<p className="mt-1 text-muted-foreground">
{totalCount.toLocaleString()} letters by Śrīla Prabhupāda (1947–1977)
</p>
</PageHeader>
<main className="max-w-4xl mx-auto px-6 py-8 space-y-6">
<LettersNav currentView={view} />
<LettersBrowser
currentView={view}
years={years}
recipients={recipients}
locations={locations}
/>
</main>
</div>
);
}
+65
View File
@@ -0,0 +1,65 @@
export const dynamic = "force-dynamic";
import Link from "next/link";
import { notFound } from "next/navigation";
import { getLettersByRecipient } from "@/lib/letters";
import { PageHeader } from "@/components/page-header";
import { Card, CardContent } from "@/components/ui/card";
export default async function LettersByRecipientPage({
params,
}: {
params: Promise<{ name: string }>;
}) {
const { name: encodedName } = await params;
const name = decodeURIComponent(encodedName);
const letters = await getLettersByRecipient(name);
if (letters.length === 0) notFound();
return (
<div className="min-h-screen bg-background">
<PageHeader>
<Link
href="/letters?view=recipient"
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
>
&larr; Letters by Recipient
</Link>
<h1 className="mt-3 text-3xl font-bold text-foreground">
Letters to or including {name}
</h1>
<p className="mt-1 text-muted-foreground">
{letters.length} {letters.length === 1 ? "letter" : "letters"}
</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">
{letters.map((letter) => (
<li key={letter.slug}>
<Link
href={`/letters/${letter.slug}`}
className="flex flex-col sm:flex-row sm:items-center sm:justify-between px-5 py-4 gap-1 sm:gap-4 hover:bg-muted transition-colors"
>
<div className="min-w-0">
<p className="font-medium text-foreground">
To: {letter.recipientDisplay}
</p>
<p className="text-sm text-muted-foreground">
{letter.date || "Undated"}
{letter.location ? ` · ${letter.location}` : ""}
</p>
</div>
</Link>
</li>
))}
</ul>
</CardContent>
</Card>
</main>
</div>
);
}
+66
View File
@@ -0,0 +1,66 @@
export const dynamic = "force-dynamic";
import Link from "next/link";
import { notFound } from "next/navigation";
import { getLettersByYear } from "@/lib/letters";
import { PageHeader } from "@/components/page-header";
import { Card, CardContent } from "@/components/ui/card";
export default async function LettersByYearPage({
params,
}: {
params: Promise<{ year: string }>;
}) {
const { year: yearStr } = await params;
const year = parseInt(yearStr, 10);
if (isNaN(year)) notFound();
const letters = await getLettersByYear(year);
if (letters.length === 0) notFound();
return (
<div className="min-h-screen bg-background">
<PageHeader>
<Link
href="/letters?view=year"
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
>
&larr; Letters by Year
</Link>
<h1 className="mt-3 text-3xl font-bold text-foreground">
Letters from {year}
</h1>
<p className="mt-1 text-muted-foreground">
{letters.length} {letters.length === 1 ? "letter" : "letters"}
</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">
{letters.map((letter) => (
<li key={letter.slug}>
<Link
href={`/letters/${letter.slug}`}
className="flex flex-col sm:flex-row sm:items-center sm:justify-between px-5 py-4 gap-1 sm:gap-4 hover:bg-muted transition-colors"
>
<div className="min-w-0">
<p className="font-medium text-foreground">
To: {letter.recipientDisplay}
</p>
<p className="text-sm text-muted-foreground">
{letter.date}
{letter.location ? ` · ${letter.location}` : ""}
</p>
</div>
</Link>
</li>
))}
</ul>
</CardContent>
</Card>
</main>
</div>
);
}
+223
View File
@@ -0,0 +1,223 @@
export const dynamic = "force-dynamic";
import Link from "next/link";
import { notFound } from "next/navigation";
import {
getMagazineContent,
getMagazineMeta,
getMagazineSidebarItems,
slugToBookCode,
type MagazineSidebarItem,
} from "@/lib/magazines";
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";
import { MobileNav, type MobileNavGroup } from "@/components/mobile-nav";
export default async function MagazineIssuePage({
params,
}: {
params: Promise<{ slug: string; issue: string }>;
}) {
const { slug, issue: issueSlug } = await params;
const bookCode = slugToBookCode(slug);
const [meta, content, sidebarItems] = await Promise.all([
getMagazineMeta(bookCode),
getMagazineContent(bookCode, issueSlug),
getMagazineSidebarItems(bookCode),
]);
if (!meta || !content) notFound();
const navItems = sidebarItems.filter((item) => item.type !== "heading");
const currentIdx = navItems.findIndex((item) => item.slug === issueSlug);
const prev = currentIdx > 0 ? navItems[currentIdx - 1] : null;
const next =
currentIdx < navItems.length - 1 ? navItems[currentIdx + 1] : null;
return (
<div className="min-h-screen bg-background">
<PageHeader sticky wide>
<Link
href={`/magazines/${slug}`}
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
>
&larr; {meta.title}
</Link>
<h1 className="mt-3 text-2xl font-bold text-foreground">
{content.title}
</h1>
</PageHeader>
<div className="w-full md:max-w-6xl mx-auto flex">
<IssueSidebar
items={sidebarItems}
currentSlug={issueSlug}
magSlug={slug}
/>
<main className="flex-1 min-w-0 px-6 py-8 space-y-8">
<IssueNav
prev={prev}
next={next}
navItems={navItems}
currentSlug={issueSlug}
magSlug={slug}
magTitle={meta.title}
showMobileNav
/>
<Card>
<CardContent className="py-8 px-6 sm:px-8">
<div className="space-y-4">
{content.paragraphs.map((paragraph, i) => (
<div
key={i}
className="text-base text-foreground leading-relaxed"
dangerouslySetInnerHTML={{ __html: paragraph }}
/>
))}
</div>
</CardContent>
</Card>
<IssueNav
prev={prev}
next={next}
navItems={navItems}
currentSlug={issueSlug}
magSlug={slug}
magTitle={meta.title}
/>
</main>
</div>
</div>
);
}
function IssueSidebar({
items,
currentSlug,
magSlug,
}: {
items: MagazineSidebarItem[];
currentSlug: string;
magSlug: string;
}) {
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">
<h2 className="text-xs font-bold uppercase tracking-wider text-muted-foreground mb-3 px-2">
Issues
</h2>
<nav className="flex flex-col gap-0.5">
{items.map((item, i) =>
item.type === "heading" ? (
<h3
key={`item-${i}`}
className="text-xs font-bold uppercase tracking-wider text-muted-foreground mt-4 mb-1 px-2"
>
{item.label}
</h3>
) : (
<Link
key={`item-${i}`}
href={`/magazines/${magSlug}/${item.slug}`}
className={cn(
"px-2 py-1.5 rounded-md text-sm transition-colors truncate",
item.slug === currentSlug
? "bg-primary/10 text-primary font-medium"
: "text-muted-foreground hover:bg-muted hover:text-foreground",
)}
title={item.label}
>
{item.label}
</Link>
),
)}
</nav>
</aside>
);
}
function IssueNav({
prev,
next,
navItems,
currentSlug,
magSlug,
magTitle,
showMobileNav = false,
}: {
prev: MagazineSidebarItem | null;
next: MagazineSidebarItem | null;
navItems: MagazineSidebarItem[];
currentSlug: string;
magSlug: string;
magTitle: string;
showMobileNav?: boolean;
}) {
const mobileNavGroups: MobileNavGroup[] = [];
if (showMobileNav && navItems.length > 0) {
mobileNavGroups.push({
title: "Issues",
items: navItems.map((i) => ({
slug: i.slug,
label: i.label,
href: `/magazines/${magSlug}/${i.slug}`,
type: i.type,
})),
});
}
return (
<div className="flex items-center justify-between gap-3">
<div className="flex items-center gap-2">
{showMobileNav && (
<MobileNav
groups={mobileNavGroups}
currentSlug={currentSlug}
bookTitle={magTitle}
/>
)}
{prev ? (
<Link
href={`/magazines/${magSlug}/${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.label}
</span>
<span className="sm:hidden">Previous</span>
</Link>
) : (
<div className="hidden lg:block" />
)}
</div>
{next ? (
<Link
href={`/magazines/${magSlug}/${next.slug}`}
className={cn(
buttonVariants({ variant: "outline", size: "sm" }),
"gap-1.5",
)}
>
<span className="hidden sm:inline truncate max-w-[180px]">
{next.label}
</span>
<span className="sm:hidden">Next</span>
<ChevronRight className="size-4" />
</Link>
) : (
<div />
)}
</div>
);
}
+96
View File
@@ -0,0 +1,96 @@
export const dynamic = "force-dynamic";
import Link from "next/link";
import { notFound } from "next/navigation";
import {
getMagazineMeta,
slugToBookCode,
type MagazineChapterEntry,
} from "@/lib/magazines";
import { PageHeader } from "@/components/page-header";
import { Card, CardContent } from "@/components/ui/card";
export default async function MagazineIndexPage({
params,
}: {
params: Promise<{ slug: string }>;
}) {
const { slug } = await params;
const bookCode = slugToBookCode(slug);
const meta = await getMagazineMeta(bookCode);
if (!meta) notFound();
return (
<div className="min-h-screen bg-background">
<PageHeader>
<Link
href="/magazines"
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
>
&larr; Magazines
</Link>
<h1 className="mt-3 text-3xl font-bold text-foreground">
{meta.title}
</h1>
<p className="mt-1 text-muted-foreground">{meta.author}</p>
</PageHeader>
<main className="max-w-3xl mx-auto px-6 py-8 space-y-8">
{meta.description && (
<p className="text-muted-foreground">{meta.description}</p>
)}
{meta.chapters.map((ch: MagazineChapterEntry, idx: number) => {
if ("slug" in ch && !("subChapters" in ch)) {
return (
<Card key={ch.slug}>
<CardContent className="p-0">
<Link
href={`/magazines/${slug}/${ch.slug}`}
className="flex items-center px-5 py-4 hover:bg-muted transition-colors"
>
<p className="font-medium text-foreground">{ch.title}</p>
</Link>
</CardContent>
</Card>
);
}
if ("subChapters" in ch) {
const group = ch as {
title: string;
subChapters: { slug: string; title: string }[];
};
return (
<div key={`group-${idx}`}>
<h2 className="text-sm font-bold uppercase tracking-wider text-muted-foreground mb-3">
{group.title}
</h2>
<Card className="divide-y divide-border">
<CardContent className="p-0">
<ul className="divide-y divide-border">
{group.subChapters.map((sc) => (
<li key={sc.slug}>
<Link
href={`/magazines/${slug}/${sc.slug}`}
className="flex items-center px-5 py-3 hover:bg-muted transition-colors"
>
<p className="text-sm font-medium text-foreground">
{sc.title}
</p>
</Link>
</li>
))}
</ul>
</CardContent>
</Card>
</div>
);
}
return null;
})}
</main>
</div>
);
}
+110
View File
@@ -0,0 +1,110 @@
export const dynamic = "force-dynamic";
import Link from "next/link";
import { PageHeader } from "@/components/page-header";
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardContent,
} from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { getAllMagazines, bookCodeToSlug } from "@/lib/magazines";
export default async function MagazinesPage() {
const magazines = await getAllMagazines();
// Group magazines by flag
const grouped: Record<string, typeof magazines> = {};
for (const mag of magazines) {
const key = mag.flag ?? "Other";
if (!grouped[key]) grouped[key] = [];
grouped[key].push(mag);
}
// Define display order for groups
const groupOrder = ["Pre 1978", "Other"];
const groupLabels: Record<string, string> = {
"Pre 1978": "Pre 1978 Editions",
Other: "Other Editions",
};
const sortedGroups = Object.keys(grouped).sort(
(a, b) => groupOrder.indexOf(a) - groupOrder.indexOf(b),
);
// If there's only one group, don't show group headings
const showGroupHeadings = sortedGroups.length > 1;
return (
<div className="min-h-screen bg-background">
<PageHeader>
<Link
href="/"
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
>
&larr; Home
</Link>
<h1 className="mt-3 text-3xl font-bold text-foreground">Magazines</h1>
<p className="mt-1 text-muted-foreground">
Back to Godhead and other periodicals by Śrīla Prabhupāda
</p>
</PageHeader>
<main className="max-w-6xl mx-auto px-6 py-8 space-y-10">
{sortedGroups.map((group) => (
<div key={group}>
{showGroupHeadings && (
<h2 className="text-sm font-bold uppercase tracking-wider text-muted-foreground mb-4">
{groupLabels[group] ?? group}
</h2>
)}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{grouped[group].map((mag) => (
<Link
key={mag.book}
href={`/magazines/${bookCodeToSlug(mag.book)}`}
className="block h-full"
>
<Card className="h-full transition-all hover:shadow-md hover:ring-foreground/20">
<CardHeader className="pb-2">
<CardTitle className="text-base font-bold leading-snug">
{mag.title}
</CardTitle>
{mag.description && (
<CardDescription className="text-xs line-clamp-3">
{mag.description}
</CardDescription>
)}
</CardHeader>
<CardContent className="pt-0">
<div className="flex flex-wrap items-center gap-2 text-sm">
{mag.flag && (
<Badge variant="secondary" className="text-xs">
{mag.flag}
</Badge>
)}
{mag.year && (
<Badge variant="secondary" className="text-xs">
Since {mag.year}
</Badge>
)}
{mag.totalIssues > 0 && (
<span className="text-muted-foreground text-xs">
{mag.totalIssues} issues
</span>
)}
</div>
</CardContent>
</Card>
</Link>
))}
</div>
</div>
))}
</main>
</div>
);
}
+71 -14
View File
@@ -16,6 +16,8 @@ import {
PenLine,
FileStack,
NotebookPen,
Newspaper,
Mail,
} from "lucide-react";
const allowRtf = process.env.ALLOW_RTF === "true";
@@ -27,11 +29,11 @@ export default function Home() {
<Logo height={56} className="mb-1" />
</PageHeader>
<main className="max-w-3xl mx-auto px-6 py-8">
<div className="grid gap-4">
<main className="max-w-6xl mx-auto px-6 py-8">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{/* Structured Books (JSON) */}
<Link href="/books" className="block group">
<Card className="transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<Link href="/books" className="block group h-full">
<Card className="h-full transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<CardHeader>
<div className="flex items-center gap-3">
<div className="flex items-center justify-center size-10 rounded-lg bg-primary/10 text-primary">
@@ -58,8 +60,8 @@ export default function Home() {
</Link>
{/* Essays */}
<Link href="/essays" className="block group">
<Card className="transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<Link href="/essays" className="block group h-full">
<Card className="h-full transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<CardHeader>
<div className="flex items-center gap-3">
<div className="flex items-center justify-center size-10 rounded-lg bg-primary/10 text-primary">
@@ -83,9 +85,64 @@ export default function Home() {
</Card>
</Link>
{/* Magazines */}
<Link href="/magazines" className="block group h-full">
<Card className="h-full transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<CardHeader>
<div className="flex items-center gap-3">
<div className="flex items-center justify-center size-10 rounded-lg bg-primary/10 text-primary">
<Newspaper className="size-5" />
</div>
<div className="flex-1 min-w-0">
<CardTitle className="text-xl font-bold">
Magazines
</CardTitle>
<CardDescription>
Back to Godhead &amp; other periodicals
</CardDescription>
</div>
</div>
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground">
The original Back to Godhead magazine founded by Śrīla
Prabhupāda in 1944 — 29 issues across 3 volumes with 89
articles on Kṛṣṇa consciousness, Vedic philosophy, and
spiritual life.
</p>
</CardContent>
</Card>
</Link>
{/* Letters */}
<Link href="/letters" className="block group h-full">
<Card className="h-full transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<CardHeader>
<div className="flex items-center gap-3">
<div className="flex items-center justify-center size-10 rounded-lg bg-primary/10 text-primary">
<Mail className="size-5" />
</div>
<div className="flex-1 min-w-0">
<CardTitle className="text-xl font-bold">Letters</CardTitle>
<CardDescription>
6,800+ letters (1947–1977)
</CardDescription>
</div>
</div>
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground">
Śrīla Prabhupāda&apos;s personal correspondence — over 6,800
letters to disciples, Godbrothers, government officials, and
well-wishers. Browse by year, recipient, or location.
</p>
</CardContent>
</Card>
</Link>
{/* Journals */}
<Link href="/journals" className="block group">
<Card className="transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<Link href="/journals" className="block group h-full">
<Card className="h-full transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<CardHeader>
<div className="flex items-center gap-3">
<div className="flex items-center justify-center size-10 rounded-lg bg-primary/10 text-primary">
@@ -113,8 +170,8 @@ export default function Home() {
</Link>
{/* Glossary */}
<Link href="/glossary" className="block group">
<Card className="transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<Link href="/glossary" className="block group h-full">
<Card className="h-full transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<CardHeader>
<div className="flex items-center gap-3">
<div className="flex items-center justify-center size-10 rounded-lg bg-primary/10 text-primary">
@@ -141,8 +198,8 @@ export default function Home() {
</Link>
{/* Other Documents */}
<Link href="/other-documents" className="block group">
<Card className="transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<Link href="/other-documents" className="block group h-full">
<Card className="h-full transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<CardHeader>
<div className="flex items-center gap-3">
<div className="flex items-center justify-center size-10 rounded-lg bg-primary/10 text-primary">
@@ -171,8 +228,8 @@ export default function Home() {
{/* RTF Document Viewer — only visible when ALLOW_RTF=true */}
{allowRtf && (
<Link href="/rtfs" className="block group">
<Card className="transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<Link href="/rtfs" className="block group h-full">
<Card className="h-full transition-all group-hover:shadow-md group-hover:ring-foreground/20">
<CardHeader>
<div className="flex items-center gap-3">
<div className="flex items-center justify-center size-10 rounded-lg bg-primary/10 text-primary">