-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.tsx
84 lines (78 loc) · 2.13 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
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
80
81
82
83
84
import MarkdownContent from "@/components/RenderMarkdown";
import { getAllPosts, getPostBySlug } from "@/lib/api";
import { formatDateString } from "@/utils";
import { Metadata } from "next";
import Link from "next/link";
import React from "react";
interface Props {
params: {
slug: string;
};
}
export async function generateMetadata({ params }: Props): Promise<Metadata> {
return {
title: getPostBySlug(params.slug).frontmatter.title,
};
}
export default async function Post({ params }: { params: { slug: string } }) {
const post = getPostBySlug(params.slug);
const allPosts = getAllPosts();
const postIndex = allPosts.findIndex(
(post) => post.fields.slug === params.slug
);
const [previous, next] = [allPosts[postIndex + 1], allPosts[postIndex - 1]];
const {
frontmatter: { title, date, description },
html,
} = post;
return (
<div id="home" className="panel special min-h-screen p-8 md:p-20">
<div id="post-main">
<div id="blog-title">
<Link
style={{
textDecoration: "none",
}}
href="/blog"
>
<h1>{`Nate's Blog`}</h1>
</Link>
<hr />
</div>
<div className="post">
<header>
<h2 id="post-title">{title}</h2>
<p>{description}</p>
<time className="published" dateTime={date}>
{formatDateString(date)}
</time>
</header>
<MarkdownContent content={html} />
</div>
<ul
style={{
display: `flex`,
flexWrap: `wrap`,
justifyContent: `space-between`,
listStyle: `none`,
padding: "2em",
}}
>
{previous && (
<li>
<Link href={previous.fields.slug}>
{" "}
{previous.frontmatter.title}{" "}
</Link>{" "}
</li>
)}
{next && (
<li>
<Link href={next.fields.slug}> {next.frontmatter.title} </Link>
</li>
)}
</ul>
</div>
</div>
);
}