|
| 1 | +import { MermaidDiagram } from "@/components/mermaid-diagram" |
| 2 | +import { ChevronRight } from "lucide-react" |
| 3 | +import Link from "next/link" |
| 4 | +import { Button } from "@/components/ui/button" |
| 5 | +import { getFlatSections } from "@/lib/book-data-server" |
| 6 | +import { parseMarkdownFile, extractMermaidDiagrams } from "@/lib/markdown" |
| 7 | +import { notFound } from "next/navigation" |
| 8 | +import path from "path" |
| 9 | + |
| 10 | +export default async function PrefacePage() { |
| 11 | + // Get the flat section list for navigation to first chapter |
| 12 | + const flat = getFlatSections() |
| 13 | + const next = flat.length > 0 ? flat[0] : null |
| 14 | + |
| 15 | + // Load and parse markdown |
| 16 | + let markdownData |
| 17 | + try { |
| 18 | + const filePath = path.join(process.cwd(), '..', 'book', 'preface.md') |
| 19 | + markdownData = await parseMarkdownFile(filePath) |
| 20 | + } catch (error) { |
| 21 | + console.error('Error loading preface:', error) |
| 22 | + notFound() |
| 23 | + } |
| 24 | + |
| 25 | + const { frontmatter, content, htmlContent } = markdownData |
| 26 | + |
| 27 | + // Extract mermaid diagrams |
| 28 | + const mermaidDiagrams = extractMermaidDiagrams(content) |
| 29 | + |
| 30 | + return ( |
| 31 | + <article className="py-12 px-6 lg:px-12 max-w-3xl"> |
| 32 | + {/* Breadcrumb */} |
| 33 | + <div className="flex items-center gap-2 text-sm text-muted-foreground mb-8"> |
| 34 | + <Link href="/" className="hover:text-foreground transition-colors"> |
| 35 | + Home |
| 36 | + </Link> |
| 37 | + <span>/</span> |
| 38 | + <span>Preface</span> |
| 39 | + </div> |
| 40 | + |
| 41 | + {/* Header */} |
| 42 | + <header className="mb-12"> |
| 43 | + <h1 className="text-3xl sm:text-4xl font-bold tracking-tight mb-4 text-balance"> |
| 44 | + {frontmatter.title || 'Preface'} |
| 45 | + </h1> |
| 46 | + {frontmatter.abstract && ( |
| 47 | + <p className="text-lg text-muted-foreground"> |
| 48 | + {frontmatter.abstract} |
| 49 | + </p> |
| 50 | + )} |
| 51 | + </header> |
| 52 | + |
| 53 | + {/* Content */} |
| 54 | + <div |
| 55 | + className="prose prose-invert prose-green max-w-none" |
| 56 | + dangerouslySetInnerHTML={{ __html: htmlContent }} |
| 57 | + /> |
| 58 | + |
| 59 | + {/* Mermaid diagrams */} |
| 60 | + {mermaidDiagrams.map((diagram, index) => ( |
| 61 | + <div key={index} className="my-8"> |
| 62 | + <MermaidDiagram |
| 63 | + chart={diagram} |
| 64 | + caption={`Figure ${index + 1}`} |
| 65 | + /> |
| 66 | + </div> |
| 67 | + ))} |
| 68 | + |
| 69 | + {/* Navigation */} |
| 70 | + <nav className="mt-16 pt-8 border-t border-border flex items-center justify-between"> |
| 71 | + <Button variant="ghost" disabled className="text-muted-foreground"> |
| 72 | + Previous |
| 73 | + </Button> |
| 74 | + {next ? ( |
| 75 | + <Button variant="ghost" asChild> |
| 76 | + <Link href={next.href} className="flex items-center gap-2"> |
| 77 | + <span className="hidden sm:inline">Start Reading: {next.sectionTitle}</span> |
| 78 | + <span className="sm:hidden">Next</span> |
| 79 | + <ChevronRight className="h-4 w-4" /> |
| 80 | + </Link> |
| 81 | + </Button> |
| 82 | + ) : ( |
| 83 | + <Button variant="ghost" disabled className="text-muted-foreground"> |
| 84 | + Next |
| 85 | + <ChevronRight className="h-4 w-4 ml-2" /> |
| 86 | + </Button> |
| 87 | + )} |
| 88 | + </nav> |
| 89 | + </article> |
| 90 | + ) |
| 91 | +} |
| 92 | + |
| 93 | +export async function generateMetadata() { |
| 94 | + try { |
| 95 | + const filePath = path.join(process.cwd(), '..', 'book', 'preface.md') |
| 96 | + const { frontmatter } = await parseMarkdownFile(filePath) |
| 97 | + |
| 98 | + return { |
| 99 | + title: `${frontmatter.title || 'Preface'} | Agentic Coding Playbook`, |
| 100 | + description: frontmatter.abstract || 'Preface to the Agentic Coding Playbook', |
| 101 | + } |
| 102 | + } catch (error) { |
| 103 | + return { |
| 104 | + title: 'Preface | Agentic Coding Playbook', |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments