|
1 |
| -import { notFound } from "next/navigation"; |
2 |
| -import { allBlogs } from "contentlayer/generated"; |
| 1 | +import metadata from "@/util/metadata"; |
3 | 2 | import type { Metadata } from "next";
|
| 3 | +import { notFound } from "next/navigation"; |
| 4 | +import { blogPosts } from "#site/content"; |
4 | 5 | import { Mdx } from "./components/mdx";
|
5 |
| -import metadata from "@/util/metadata"; |
6 | 6 | import Supplement from "./components/supplement";
|
7 | 7 |
|
8 | 8 | interface Props {
|
9 |
| - params: { |
10 |
| - slug: string; |
11 |
| - }; |
| 9 | + params: { |
| 10 | + slug: string; |
| 11 | + }; |
12 | 12 | }
|
13 | 13 |
|
14 |
| -export default async function DocPage({ params }: Props) { |
15 |
| - const post = await getDocFromParams({ params }); |
16 |
| - |
17 |
| - if (!post) { |
18 |
| - notFound(); |
19 |
| - } |
20 |
| - |
21 |
| - return ( |
22 |
| - <div className="flex flex-col mt-5 gap-1"> |
23 |
| - <h1 className="break-all text-3xl font-black bg-gradient-to-r from-slate-600 via-slate-300 to-slate-700 inline-block text-transparent bg-clip-text"> |
24 |
| - {post.title} |
25 |
| - </h1> |
26 |
| - <time className="text-gray-500 text-sm mt-2 ml-auto">{post.date}</time> |
27 |
| - <Mdx code={post.body.code} /> |
28 |
| - <Supplement /> |
29 |
| - </div> |
30 |
| - ); |
| 14 | +export default function DocPage({ params }: Props) { |
| 15 | + const post = getPageBySlug(params.slug); |
| 16 | + |
| 17 | + if (!post) { |
| 18 | + notFound(); |
| 19 | + } |
| 20 | + |
| 21 | + return ( |
| 22 | + <div className="flex flex-col mt-5 gap-2"> |
| 23 | + <h1 className="text-5xl font-black text-primary break-keep">{post.title}</h1> |
| 24 | + <time className="text-primary font-medium text-sm mt-2 mb-10 ml-auto">{post.date}</time> |
| 25 | + <Mdx code={post.body} /> |
| 26 | + <Supplement /> |
| 27 | + </div> |
| 28 | + ); |
31 | 29 | }
|
32 | 30 |
|
33 |
| -async function getDocFromParams({ params }: Props) { |
34 |
| - const doc = allBlogs.find((doc) => doc.slug === params.slug); |
35 |
| - |
36 |
| - return doc ?? null; |
| 31 | +function getPageBySlug(slug: string) { |
| 32 | + return blogPosts.find((page) => page.slug === slug); |
37 | 33 | }
|
38 | 34 |
|
39 | 35 | export async function generateStaticParams() {
|
40 |
| - return allBlogs.map((doc) => ({ |
41 |
| - slug: doc.slug, |
42 |
| - })); |
| 36 | + return blogPosts.map((doc) => ({ |
| 37 | + slug: doc.slug, |
| 38 | + })); |
43 | 39 | }
|
44 | 40 |
|
45 | 41 | export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
46 |
| - const doc = await getDocFromParams({ params }); |
47 |
| - |
48 |
| - if (!doc) { |
49 |
| - return {}; |
50 |
| - } |
51 |
| - |
52 |
| - return metadata({ |
53 |
| - title: doc.title, |
54 |
| - description: doc.description, |
55 |
| - path: `/blog/${doc.slug}`, |
56 |
| - image: `/${doc.thumbnailUrl}`, |
57 |
| - }); |
| 42 | + const doc = getPageBySlug(params.slug); |
| 43 | + |
| 44 | + if (!doc) { |
| 45 | + return {}; |
| 46 | + } |
| 47 | + |
| 48 | + return metadata({ |
| 49 | + title: doc.title, |
| 50 | + description: doc.description, |
| 51 | + path: doc.permalink, |
| 52 | + image: `${doc.thumbnailUrl}`, |
| 53 | + }); |
58 | 54 | }
|
0 commit comments