www/components/recent-posts.tsx

39 lines
1.4 KiB
TypeScript
Raw Normal View History

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";
import { IPostMeta } from "../lib/slug";
2022-04-28 01:55:18 +00:00
import style from '../styles/recent-posts.module.css';
2022-10-05 03:41:59 +00:00
function RecentPosts({ postsMeta }: { postsMeta: IPostMeta[] }) {
if (!postsMeta.length)
return <></>;
2022-05-15 13:56:45 +00:00
return (
<div className='block'>
<div className='h2'>Recent Posts</div>
<div className={style.container}>
{postsMeta?.slice(0, 10)
.map((post: any) => {
return <div className={style.block} key={post.slug}>
<span className={style.postDate}>
2022-10-05 03:41:59 +00:00
{date.toRelativeDate(new Date(post.created_at))}
2022-05-15 13:56:45 +00:00
</span>
2022-10-05 03:41:59 +00:00
<div className={style.postTitle}>
<Link href={`/posts/${post.slug}`}>
{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
{
postsMeta.length > 10 &&
<div className={style.more}>
<Link href='/posts'>
<a className='h5'>More...</a>
</Link>
</div>
}
</div>
2022-04-28 01:55:18 +00:00
);
}
export default RecentPosts;