|
| 1 | +import { CustomMDX } from "@/content/mdx"; |
| 2 | +import { getUseCasePages } from "@/content/utils"; |
| 3 | +import { BASE_URL, getPageMetadata } from "@/lib/metadata/shared-metadata"; |
| 4 | +import { |
| 5 | + createJsonLDGraph, |
| 6 | + getJsonLDBlogPosting, |
| 7 | + getJsonLDBreadcrumbList, |
| 8 | + getJsonLDFAQPage, |
| 9 | + getJsonLDHowTo, |
| 10 | + getJsonLDOrganization, |
| 11 | + getJsonLDWebPage, |
| 12 | +} from "@/lib/metadata/structured-data"; |
| 13 | +import type { Metadata } from "next"; |
| 14 | +import Image from "next/image"; |
| 15 | +import { notFound } from "next/navigation"; |
| 16 | +import { ContentMetadata } from "../../content-metadata"; |
| 17 | +import { ContentPagination } from "../../content-pagination"; |
| 18 | + |
| 19 | +export const dynamicParams = false; |
| 20 | + |
| 21 | +export async function generateStaticParams() { |
| 22 | + const posts = getUseCasePages(); |
| 23 | + |
| 24 | + return posts.map((post) => ({ |
| 25 | + slug: post.slug, |
| 26 | + })); |
| 27 | +} |
| 28 | + |
| 29 | +export async function generateMetadata({ |
| 30 | + params, |
| 31 | +}: { |
| 32 | + params: Promise<{ slug: string }>; |
| 33 | +}): Promise<Metadata | undefined> { |
| 34 | + const { slug } = await params; |
| 35 | + const post = getUseCasePages().find((post) => post.slug === slug); |
| 36 | + if (!post) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + const metadata = getPageMetadata(post, "use-case"); |
| 41 | + |
| 42 | + return metadata; |
| 43 | +} |
| 44 | + |
| 45 | +export default async function UseCase({ |
| 46 | + params, |
| 47 | +}: { |
| 48 | + params: Promise<{ slug: string }>; |
| 49 | +}) { |
| 50 | + const { slug } = await params; |
| 51 | + const posts = getUseCasePages().sort( |
| 52 | + (a, b) => |
| 53 | + b.metadata.publishedAt.getTime() - a.metadata.publishedAt.getTime(), |
| 54 | + ); |
| 55 | + const postIndex = posts.findIndex((post) => post.slug === slug); |
| 56 | + const post = posts[postIndex]; |
| 57 | + const previousPost = posts[postIndex - 1]; |
| 58 | + const nextPost = posts[postIndex + 1]; |
| 59 | + |
| 60 | + if (!post) { |
| 61 | + notFound(); |
| 62 | + } |
| 63 | + |
| 64 | + const jsonLDGraph = createJsonLDGraph([ |
| 65 | + getJsonLDOrganization(), |
| 66 | + getJsonLDWebPage(post), |
| 67 | + getJsonLDBlogPosting(post, "use-case"), |
| 68 | + getJsonLDBreadcrumbList([ |
| 69 | + { name: "Home", url: BASE_URL }, |
| 70 | + { name: "Use Cases", url: `${BASE_URL}/use-case` }, |
| 71 | + { name: post.metadata.title, url: `${BASE_URL}/use-case/${slug}` }, |
| 72 | + ]), |
| 73 | + getJsonLDHowTo(post), |
| 74 | + getJsonLDFAQPage(post), |
| 75 | + ]); |
| 76 | + |
| 77 | + return ( |
| 78 | + <section className="prose dark:prose-invert max-w-none"> |
| 79 | + <script |
| 80 | + type="application/ld+json" |
| 81 | + suppressHydrationWarning |
| 82 | + // biome-ignore lint/security/noDangerouslySetInnerHtml: jsonLd |
| 83 | + dangerouslySetInnerHTML={{ |
| 84 | + __html: JSON.stringify(jsonLDGraph).replace(/</g, "\\u003c"), |
| 85 | + }} |
| 86 | + /> |
| 87 | + <h1>{post.metadata.title}</h1> |
| 88 | + <ContentMetadata data={post} /> |
| 89 | + {post.metadata.image ? ( |
| 90 | + <div className="relative aspect-video w-full overflow-hidden border border-border"> |
| 91 | + <Image |
| 92 | + src={post.metadata.image} |
| 93 | + alt={post.metadata.title} |
| 94 | + fill |
| 95 | + className="object-contain" |
| 96 | + /> |
| 97 | + </div> |
| 98 | + ) : null} |
| 99 | + <CustomMDX source={post.content} /> |
| 100 | + <ContentPagination |
| 101 | + previousPost={previousPost} |
| 102 | + nextPost={nextPost} |
| 103 | + prefix="/use-case" |
| 104 | + /> |
| 105 | + </section> |
| 106 | + ); |
| 107 | +} |
0 commit comments