|
| 1 | +import { notFound } from "next/navigation"; |
| 2 | +import { getStoriesPosts } from "../utils"; |
| 3 | +import { CustomMDX } from "@/components/mdx"; |
| 4 | +import Header from "@/components/header"; |
| 5 | +import Footer from "@/components/footer"; |
| 6 | +import { canela_regu } from "@/lib/fonts"; |
| 7 | +import { formatDate } from "../utils"; |
| 8 | + |
| 9 | +export async function generateStaticParams() { |
| 10 | + let posts = getStoriesPosts(); |
| 11 | + |
| 12 | + return posts.map((post) => ({ |
| 13 | + slug: post.slug, |
| 14 | + })); |
| 15 | +} |
| 16 | + |
| 17 | +export function generateMetadata({ params }) { |
| 18 | + let post = getStoriesPosts().find((post) => post.slug === params.slug); |
| 19 | + if (!post) { |
| 20 | + return; |
| 21 | + } |
| 22 | + |
| 23 | + let { |
| 24 | + title, |
| 25 | + publishedAt: publishedTime, |
| 26 | + summary: description, |
| 27 | + image, |
| 28 | + } = post.metadata; |
| 29 | + |
| 30 | + let ogImage = image |
| 31 | + ? `https://sumitso.in${image}` |
| 32 | + : `https://sumitso.in/og?title=${encodeURIComponent(title)}`; |
| 33 | + |
| 34 | + return { |
| 35 | + title, |
| 36 | + description, |
| 37 | + openGraph: { |
| 38 | + title, |
| 39 | + description, |
| 40 | + type: "article", |
| 41 | + publishedTime, |
| 42 | + url: `https://sumitso.in/stories/${post.slug}`, |
| 43 | + images: [ |
| 44 | + { |
| 45 | + url: ogImage, |
| 46 | + }, |
| 47 | + ], |
| 48 | + }, |
| 49 | + twitter: { |
| 50 | + card: "summary_large_image", |
| 51 | + title, |
| 52 | + description, |
| 53 | + images: [ogImage], |
| 54 | + }, |
| 55 | + }; |
| 56 | +} |
| 57 | + |
| 58 | +export default function StoriesPost({ params }) { |
| 59 | + let posts = getStoriesPosts(); |
| 60 | + let post = posts.find((post) => post.slug === params.slug); |
| 61 | + |
| 62 | + if (!post) { |
| 63 | + notFound(); |
| 64 | + } |
| 65 | + |
| 66 | + return ( |
| 67 | + <div className="min-h-screen bg-gradient-to-b"> |
| 68 | + <Header /> |
| 69 | + <div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12"> |
| 70 | + <article className="prose prose-lg max-w-none"> |
| 71 | + <header className="mb-8"> |
| 72 | + <h1 |
| 73 | + className={`${canela_regu.className} text-4xl font-bold text-gray-900 mb-4`} |
| 74 | + > |
| 75 | + {post.metadata.title} |
| 76 | + </h1> |
| 77 | + {post.metadata.publishedAt && ( |
| 78 | + <time className="text-gray-500 text-sm"> |
| 79 | + {formatDate(post.metadata.publishedAt)} |
| 80 | + </time> |
| 81 | + )} |
| 82 | + </header> |
| 83 | + |
| 84 | + {post.metadata.image && ( |
| 85 | + <div className="mb-8"> |
| 86 | + <img |
| 87 | + src={post.metadata.image} |
| 88 | + alt={post.metadata.title} |
| 89 | + className="w-full h-auto rounded-lg shadow-md" |
| 90 | + /> |
| 91 | + </div> |
| 92 | + )} |
| 93 | + |
| 94 | + <div className="prose prose-lg max-w-none"> |
| 95 | + <CustomMDX source={post.content} /> |
| 96 | + </div> |
| 97 | + </article> |
| 98 | + </div> |
| 99 | + <Footer /> |
| 100 | + </div> |
| 101 | + ); |
| 102 | +} |
0 commit comments