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