-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathpage.tsx
50 lines (43 loc) · 1.3 KB
/
page.tsx
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
import Header from '@/components/Header/Header'
import Project from '@/components/Project'
import ProjectNav from '@/components/ProjectNav'
import { getAllSlugs } from '@/lib/getAllSlugs'
import { getProjectBySlug } from '@/lib/getProjectBySlug'
import meta from '@content/meta.json'
import projects from '@generated/projects.json'
import type { Metadata } from 'next'
import { notFound } from 'next/navigation'
type Props = {
params: { slug: string }
}
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const project = getProjectBySlug(params.slug)
if (!project) return {}
return {
title: project.title,
description: `${project.description.slice(0, 157)}...`,
metadataBase: new URL(meta.url),
alternates: {
canonical: `/${project.slug}`
},
openGraph: {
url: `/${project.slug}`,
images: [{ url: project.images[0].src }]
}
}
}
export default async function ProjectPage({ params }: Props) {
const project = getProjectBySlug(params.slug)
if (!project) notFound()
return (
<>
<Header />
<Project project={project} />
<ProjectNav projects={projects} currentSlug={params.slug} />
</>
)
}
export async function generateStaticParams() {
const slugs = getAllSlugs()
return slugs.map((slug) => ({ slug }))
}