-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
79 lines (71 loc) · 2.15 KB
/
Copy pathpage.tsx
File metadata and controls
79 lines (71 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import type { ArticleMeta } from '@/lib/types';
import { Prose } from '@/components/Prose';
import { formatDate } from '@/lib/formatDate';
import { type Metadata } from 'next';
// import { Metadata, ResolvingMetadata } from 'next'
import { getAllArticles } from '@/lib/getAllArticles';
import Codepen from '@/components/Codepen';
import { type MDXProps } from 'mdx/types';
import Comments from '@/components/Comments';
import { notFound } from 'next/navigation';
const components = { Codepen };
export const dynamicParams = false;
export async function generateStaticParams() {
const articles = await getAllArticles();
return articles.map((articles) => ({
slug: articles.slug,
}));
}
type Props = {
params: { slug: string };
};
export async function generateMetadata({
params,
}: Props): // parent: ResolvingMetadata
Promise<Metadata> {
const {
meta,
}: {
meta: ArticleMeta;
} = require(`../../../../content/${params.slug}.mdx`);
return {
title: meta.title,
description: meta.description,
};
}
export default async function Page({ params }: Props) {
try {
const {
default: MdxPage,
meta,
}: {
default: React.ComponentType<MDXProps>;
meta: ArticleMeta;
} = require(`../../../../content/${params.slug}.mdx`);
return (
<div className="xl:relative">
<div className="mx-auto max-w-2xl 2xl:max-w-3xl">
<article>
<header className="flex flex-col">
<h1 className="font-title mt-6 ">{meta.title}</h1>
<time
dateTime={meta.date}
className="order-first flex items-center text-base text-stone-400 dark:text-stone-500 lg:text-lg"
>
<span className="h-4 w-0.5 rounded-full bg-stone-200 dark:bg-stone-500" />
<span className="ml-3">{formatDate(meta.date)}</span>
</time>
</header>
<Prose className="mt-8">
<MdxPage components={components} />
</Prose>
<Comments slug={params.slug} />
</article>
</div>
</div>
);
} catch (error) {
console.log(error);
notFound();
}
}