2022-04-27 21:55:18 -04:00
|
|
|
import Link from "next/link";
|
2024-02-13 18:01:07 -05:00
|
|
|
import { toRelativeDate } from "../lib/date";
|
2022-04-27 21:55:18 -04:00
|
|
|
import style from '../styles/recent-posts.module.css';
|
2023-10-30 00:18:38 -04:00
|
|
|
import PostsInfo from '../public/posts.json';
|
2022-04-27 21:55:18 -04:00
|
|
|
|
2024-02-13 18:01:07 -05:00
|
|
|
function PostBlock({ slug, otime, title }: { slug: string, otime: string, title: string }) {
|
|
|
|
return (
|
|
|
|
<div className={style.block}>
|
|
|
|
<span className={style.postDate}>
|
|
|
|
{toRelativeDate(new Date(otime))}
|
|
|
|
</span>
|
|
|
|
<div className={style.postTitle}>
|
|
|
|
<Link href={`/posts/${slug}`}>
|
|
|
|
{title}
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-10-30 00:18:38 -04:00
|
|
|
function RecentPosts() {
|
2024-02-13 18:01:07 -05:00
|
|
|
const posts = Object.entries(PostsInfo).reverse();
|
2023-10-30 00:18:38 -04:00
|
|
|
if (!posts.length)
|
2022-09-10 02:03:52 -04:00
|
|
|
return <></>;
|
2022-05-15 09:56:45 -04:00
|
|
|
return (
|
|
|
|
<div className='block'>
|
2024-02-13 18:01:07 -05:00
|
|
|
<h2>Recent Posts</h2>
|
2022-05-15 09:56:45 -04:00
|
|
|
<div className={style.container}>
|
2023-10-30 00:18:38 -04:00
|
|
|
{posts?.slice(0, 10)
|
2024-02-13 18:01:07 -05:00
|
|
|
.map(([slug, post]: any, i: number) => {
|
|
|
|
return (
|
|
|
|
<PostBlock
|
|
|
|
key={i}
|
|
|
|
slug={slug}
|
|
|
|
title={post.title}
|
|
|
|
otime={post.otime} />
|
|
|
|
);
|
2022-05-15 09:56:45 -04:00
|
|
|
})}
|
2022-04-27 21:55:18 -04:00
|
|
|
</div>
|
2022-05-15 09:56:45 -04:00
|
|
|
{
|
2023-10-30 00:18:38 -04:00
|
|
|
posts.length > 10 &&
|
2022-05-15 09:56:45 -04:00
|
|
|
<div className={style.more}>
|
2024-02-13 18:01:07 -05:00
|
|
|
<Link href='/posts' >More...</Link>
|
2022-05-15 09:56:45 -04:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
2022-04-27 21:55:18 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-20 00:25:34 -04:00
|
|
|
export default RecentPosts;
|