153 lines
5.4 KiB
TypeScript
153 lines
5.4 KiB
TypeScript
export const dynamic = "force-dynamic";
|
|
|
|
import type { Metadata } from "next";
|
|
import Link from "next/link";
|
|
import { notFound } from "next/navigation";
|
|
import {
|
|
getJournalMeta,
|
|
slugToBookCode,
|
|
type JournalChapterEntry,
|
|
} from "@/lib/journals";
|
|
import { ogForJournal } from "@/lib/og";
|
|
import { PageHeader } from "@/components/layout/page-header";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: {
|
|
params: Promise<{ slug: string }>;
|
|
}): Promise<Metadata> {
|
|
const { slug } = await params;
|
|
const bookCode = slugToBookCode(slug);
|
|
const meta = await getJournalMeta(bookCode);
|
|
const title = meta?.title ?? slug;
|
|
return ogForJournal(title);
|
|
}
|
|
|
|
export default async function JournalIndexPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ slug: string }>;
|
|
}) {
|
|
const { slug } = await params;
|
|
const bookCode = slugToBookCode(slug);
|
|
const meta = await getJournalMeta(bookCode);
|
|
if (!meta) notFound();
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<PageHeader>
|
|
<Link
|
|
href="/journals"
|
|
className="text-sm text-muted-foreground hover:text-foreground transition-colors"
|
|
>
|
|
← Journals
|
|
</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-5xl mx-auto px-6 py-8 space-y-8">
|
|
{meta.description && (
|
|
<p className="text-muted-foreground">{meta.description}</p>
|
|
)}
|
|
|
|
{meta.chapters.map((ch: JournalChapterEntry, idx: number) => {
|
|
// Top-level chapter with a slug (Preface, Introduction, etc.)
|
|
if ("slug" in ch && !("subChapters" in ch)) {
|
|
return (
|
|
<div key={ch.slug}>
|
|
<Card>
|
|
<CardContent className="p-0">
|
|
<Link
|
|
href={`/journals/${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>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Group with sub-chapters (may be 2 or 3 levels deep)
|
|
if ("subChapters" in ch) {
|
|
const group = ch as {
|
|
title: string;
|
|
subChapters: {
|
|
slug?: string;
|
|
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>
|
|
<div className="space-y-4">
|
|
{group.subChapters.map((sc, scIdx) => {
|
|
// Sub-chapter with its own nested sub-chapters (e.g., month → days)
|
|
if ("subChapters" in sc && sc.subChapters) {
|
|
return (
|
|
<div key={`sc-${idx}-${scIdx}`}>
|
|
<h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-2 ml-1">
|
|
{sc.title}
|
|
</h3>
|
|
<Card className="divide-y divide-border">
|
|
<CardContent className="p-0">
|
|
<ul className="divide-y divide-border">
|
|
{sc.subChapters.map((day) => (
|
|
<li key={day.slug}>
|
|
<Link
|
|
href={`/journals/${slug}/${day.slug}`}
|
|
className="flex items-center px-5 py-3 hover:bg-muted transition-colors"
|
|
>
|
|
<p className="text-sm font-medium text-foreground">
|
|
{day.title}
|
|
</p>
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Direct sub-chapter with a slug (e.g., Summary, Notice)
|
|
if ("slug" in sc && sc.slug) {
|
|
return (
|
|
<Card key={`sc-${idx}-${scIdx}`}>
|
|
<CardContent className="p-0">
|
|
<Link
|
|
href={`/journals/${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>
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
return null;
|
|
})}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return null;
|
|
})}
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|