|
| 1 | +import type { Metadata } from "next"; |
| 2 | +import { notFound } from "next/navigation"; |
| 3 | +import Link from "next/link"; |
| 4 | +import { ExternalLink, Package as PackageIcon } from "lucide-react"; |
| 5 | +import { FRAMEWORK_GUIDES, FAQ_ITEMS } from "@/lib/docs-content"; |
| 6 | +import { slugifyHeading } from "@/lib/docs-nav"; |
| 7 | +import { GUIDE_RELATED_FAQ } from "@/lib/docs-related-faq"; |
| 8 | +import { DocsCodeBlock } from "@/components/docs/docs-code-block"; |
| 9 | +import { DocsHeading } from "@/components/docs/docs-heading"; |
| 10 | +import { DocsBrandIcon } from "@/components/docs/docs-nav-icon"; |
| 11 | +import { DocsListPage } from "@/components/docs/docs-list-page"; |
| 12 | + |
| 13 | +interface PageProps { |
| 14 | + params: Promise<{ slug: string }>; |
| 15 | +} |
| 16 | + |
| 17 | +export function generateStaticParams() { |
| 18 | + return FRAMEWORK_GUIDES.map((guide) => ({ slug: guide.id })); |
| 19 | +} |
| 20 | + |
| 21 | +export async function generateMetadata({ params }: Readonly<PageProps>): Promise<Metadata> { |
| 22 | + const { slug } = await params; |
| 23 | + const guide = FRAMEWORK_GUIDES.find((g) => g.id === slug); |
| 24 | + if (!guide) return {}; |
| 25 | + return { |
| 26 | + title: guide.label, |
| 27 | + description: guide.summary, |
| 28 | + keywords: [`${guide.label} brand icons`, `${guide.label} SVG icons`, "theSVG"], |
| 29 | + openGraph: { title: guide.label, description: guide.summary, siteName: "theSVG" }, |
| 30 | + alternates: { canonical: `https://thesvg.org/docs/${guide.id}` }, |
| 31 | + }; |
| 32 | +} |
| 33 | + |
| 34 | +function PackageBadge({ href, icon, label }: Readonly<{ href: string; icon: React.ReactNode; label: string }>) { |
| 35 | + return ( |
| 36 | + <Link |
| 37 | + href={href} |
| 38 | + target="_blank" |
| 39 | + rel="noopener noreferrer" |
| 40 | + className="inline-flex items-center gap-1 rounded-full bg-muted/60 px-2 py-0.5 font-mono text-[11px] text-muted-foreground hover:text-foreground dark:bg-white/[0.04]" |
| 41 | + > |
| 42 | + {icon} |
| 43 | + {label} |
| 44 | + <ExternalLink className="h-2.5 w-2.5" /> |
| 45 | + </Link> |
| 46 | + ); |
| 47 | +} |
| 48 | + |
| 49 | +export default async function DocsGuidePage({ params }: Readonly<PageProps>) { |
| 50 | + const { slug } = await params; |
| 51 | + const guide = FRAMEWORK_GUIDES.find((g) => g.id === slug); |
| 52 | + if (!guide) notFound(); |
| 53 | + |
| 54 | + const tocItems = guide.snippets.map((s) => ({ id: slugifyHeading(s.label), label: s.label })); |
| 55 | + const relatedQuestions = GUIDE_RELATED_FAQ[guide.id] ?? []; |
| 56 | + const relatedFaq = FAQ_ITEMS.filter((item) => relatedQuestions.includes(item.question)); |
| 57 | + |
| 58 | + return ( |
| 59 | + <DocsListPage |
| 60 | + title={guide.label} |
| 61 | + tocItems={tocItems} |
| 62 | + sourceFile="src/lib/docs-content.ts" |
| 63 | + titleBadges={ |
| 64 | + <> |
| 65 | + {guide.packageName && ( |
| 66 | + <PackageBadge |
| 67 | + href={guide.npmUrl ?? "#"} |
| 68 | + icon={<PackageIcon className="h-2.5 w-2.5" />} |
| 69 | + label={guide.packageName} |
| 70 | + /> |
| 71 | + )} |
| 72 | + {guide.githubUrl && ( |
| 73 | + <PackageBadge |
| 74 | + href={guide.githubUrl} |
| 75 | + icon={<DocsBrandIcon slug="github" className="h-2.5 w-2.5" />} |
| 76 | + label="Source" |
| 77 | + /> |
| 78 | + )} |
| 79 | + </> |
| 80 | + } |
| 81 | + intro={<p className="mb-8 max-w-2xl text-sm text-muted-foreground">{guide.summary}</p>} |
| 82 | + > |
| 83 | + <div className="space-y-8"> |
| 84 | + {guide.snippets.map((snippet) => ( |
| 85 | + <section key={snippet.label} className="scroll-mt-24"> |
| 86 | + <DocsHeading id={slugifyHeading(snippet.label)}>{snippet.label}</DocsHeading> |
| 87 | + <DocsCodeBlock snippet={snippet} /> |
| 88 | + </section> |
| 89 | + ))} |
| 90 | + </div> |
| 91 | + |
| 92 | + {relatedFaq.length > 0 && ( |
| 93 | + <div className="mt-10 border-t border-border/40 pt-6 dark:border-white/[0.06]"> |
| 94 | + <h2 className="mb-3 text-sm font-semibold text-muted-foreground">Related questions</h2> |
| 95 | + <div className="space-y-3"> |
| 96 | + {relatedFaq.map((item) => ( |
| 97 | + <details key={item.question} className="group rounded-lg border border-border/40 px-3 py-2 dark:border-white/[0.06]"> |
| 98 | + <summary className="cursor-pointer list-none text-sm font-medium marker:content-none"> |
| 99 | + {item.question} |
| 100 | + </summary> |
| 101 | + <p className="mt-1.5 text-xs leading-relaxed text-muted-foreground">{item.answer}</p> |
| 102 | + </details> |
| 103 | + ))} |
| 104 | + </div> |
| 105 | + <Link |
| 106 | + href="/docs/faq" |
| 107 | + className="mt-3 inline-block text-xs text-orange-600 underline underline-offset-2 dark:text-orange-400" |
| 108 | + > |
| 109 | + See all FAQ → |
| 110 | + </Link> |
| 111 | + </div> |
| 112 | + )} |
| 113 | + </DocsListPage> |
| 114 | + ); |
| 115 | +} |
0 commit comments