-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[slug].tsx
64 lines (56 loc) · 1.53 KB
/
[slug].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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { GetStaticPaths, GetStaticProps } from 'next/types'
import resume from '../../_content/resume.json'
import Project from '../components/Project'
import ProjectNav from '../components/ProjectNav'
import type ProjectType from '../interfaces/project'
import Page from '../layouts/Page'
import {
getAllProjects,
getProjectBySlug,
getProjectSlugs
} from '../lib/content'
type Props = {
project: ProjectType
projects: { slug: string }[]
}
export default function ProjectPage({ project, projects }: Props) {
const firstImage = project.images && project.images[0];
const pageMeta = {
title: `${
project.title
} // ${resume.basics.name.toLowerCase()} { ${resume.basics.label.toLowerCase()} }`,
description: project.description,
image: firstImage ? firstImage.src : '',
slug: project.slug,
}
return (
<Page {...pageMeta}>
<Project project={project} />
<ProjectNav projects={projects} currentSlug={project.slug} />
</Page>
)
}
type Params = {
params: {
slug: string
}
}
export const getStaticProps: GetStaticProps = async ({ params }: Params) => {
const project = await getProjectBySlug(params.slug, [
'title',
'description',
'slug',
'images',
'techstack',
'links'
])
const projects = await getAllProjects(['slug', 'title', 'images'])
return { props: { project, projects } }
}
export const getStaticPaths: GetStaticPaths = () => {
const slugs = getProjectSlugs()
return {
paths: slugs.map((slug) => ({ params: { slug } })),
fallback: false
}
}