-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
44 lines (36 loc) · 1019 Bytes
/
page.tsx
File metadata and controls
44 lines (36 loc) · 1019 Bytes
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
import { news } from '@/velite';
import { notFound } from 'next/navigation';
import { Metadata } from 'next';
import { NewsPost } from '@/sections/news/NewsPost';
interface PageProps {
params: Promise<{ slug: string }>;
}
export async function generateStaticParams() {
return news.map((post) => ({
slug: post.slug.split('/').pop(), // "news/my-post" -> "my-post"
}));
}
export async function generateMetadata({
params,
}: PageProps): Promise<Metadata> {
const resolvedParams = await params;
// Velite slug is 'news/slug', params.slug is 'slug'
const post = news.find((p) => p.slug === `news/${resolvedParams.slug}`);
if (!post) {
return {
title: 'Noticia no encontrada',
};
}
return {
title: post.title,
description: post.description,
};
}
export default async function NewsPostPage({ params }: PageProps) {
const resolvedParams = await params;
const post = news.find((p) => p.slug === `news/${resolvedParams.slug}`);
if (!post) {
notFound();
}
return <NewsPost post={post} />;
}