|
| 1 | +import { Code } from "@/components/docskit/code"; |
| 2 | +import { recipes } from "@/data/recipes"; |
| 3 | +import { ArrowUpRight, Play, TestTube } from "lucide-react"; |
| 4 | +import { Button } from "@/components/ui/button"; |
| 5 | +import { Badge } from "@/components/ui/badge"; |
| 6 | +import { HoverProvider } from "@/context/hover"; |
| 7 | +import { HoverLink } from "@/components/docskit/annotations/hover"; |
| 8 | +import Link from "next/link"; |
| 9 | +import { Terminal } from "@/components/docskit/terminal"; |
| 10 | +import { InlineCode } from "@/components/docskit/inline-code"; |
| 11 | +import { Github } from "@/components/ui/icon"; |
| 12 | +import { WithNotes } from "@/components/docskit/notes"; |
| 13 | +import { SnippetResult } from "../components/snippet-result"; |
| 14 | + |
| 15 | +interface Param { |
| 16 | + id: string; |
| 17 | +} |
| 18 | + |
| 19 | +export const dynamicParams = false; |
| 20 | + |
| 21 | +export default async function Page({ |
| 22 | + params, |
| 23 | +}: { |
| 24 | + params: Param; |
| 25 | +}): Promise<JSX.Element> { |
| 26 | + const { id } = params; |
| 27 | + const recipe = recipes.find((r) => r.id === id); |
| 28 | + |
| 29 | + if (!recipe) { |
| 30 | + return <div>Recipe not found</div>; |
| 31 | + } |
| 32 | + |
| 33 | + // Dynamically import MDX content based on recipe id |
| 34 | + const Content = await import(`@/content/_recipes/${id}.mdx`).catch(() => { |
| 35 | + console.error(`Failed to load MDX content for recipe: ${id}`); |
| 36 | + return { default: () => <div>Content not found</div> }; |
| 37 | + }); |
| 38 | + |
| 39 | + const snippetCodeResult = (result: string) => { |
| 40 | + <Code |
| 41 | + codeblocks={[ |
| 42 | + { |
| 43 | + lang: "bash", |
| 44 | + value: result, |
| 45 | + meta: `-nw`, |
| 46 | + }, |
| 47 | + ]} |
| 48 | + />; |
| 49 | + }; |
| 50 | + |
| 51 | + return ( |
| 52 | + <HoverProvider> |
| 53 | + <div className="min-h-screen"> |
| 54 | + <div className="px-4 py-8"> |
| 55 | + <div className="grid grid-cols-12 gap-12"> |
| 56 | + <div className="col-span-6"> |
| 57 | + <div className="space-y-3"> |
| 58 | + <div className="flex flex-wrap gap-2"> |
| 59 | + {recipe.tags.map((tag) => ( |
| 60 | + <Badge key={tag} variant="secondary"> |
| 61 | + {tag.toUpperCase()} |
| 62 | + </Badge> |
| 63 | + ))} |
| 64 | + </div> |
| 65 | + <div className="prose max-w-none"> |
| 66 | + <Content.default |
| 67 | + components={{ |
| 68 | + HoverLink, |
| 69 | + Terminal, |
| 70 | + Code, |
| 71 | + InlineCode, |
| 72 | + WithNotes, |
| 73 | + }} |
| 74 | + /> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + |
| 79 | + {/* Sticky sidebar */} |
| 80 | + <div className="col-span-6"> |
| 81 | + <div className="sticky top-20 space-y-4"> |
| 82 | + <div className="recipe group relative w-full bg-card overflow-hidden"> |
| 83 | + <Code |
| 84 | + codeblocks={[ |
| 85 | + { |
| 86 | + lang: recipe.type, |
| 87 | + value: recipe.files[0].content, |
| 88 | + meta: `${recipe.files[0].name} -cnw`, // filename + flags |
| 89 | + }, |
| 90 | + ]} |
| 91 | + /> |
| 92 | + </div> |
| 93 | + <SnippetResult code={recipe.files[0].content as string} /> |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + </HoverProvider> |
| 100 | + ); |
| 101 | +} |
0 commit comments