File size: 1,118 Bytes
1e92f2d |
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 |
import type { InferGetStaticPropsType } from "next";
import Link from "next/link";
import Container from "../../components/container";
import distanceToNow from "../../lib/dateRelative";
import { getAllPosts } from "../../lib/getPost";
export default function NotePage({
allPosts,
}: InferGetStaticPropsType<typeof getStaticProps>) {
return (
<Container>
{allPosts.length ? (
allPosts.map((post) => (
<article key={post.slug} className="mb-10">
<Link
as={`/posts/${post.slug}`}
href="/posts/[slug]"
className="text-lg leading-6 font-bold"
>
{post.title}
</Link>
<p>{post.excerpt}</p>
<div className="text-gray-400">
<time>{distanceToNow(new Date(post.date))}</time>
</div>
</article>
))
) : (
<p>No blog posted yet :/</p>
)}
</Container>
);
}
export async function getStaticProps() {
const allPosts = getAllPosts(["slug", "title", "excerpt", "date"]);
return {
props: { allPosts },
};
}
|