38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import Link from "next/link";
|
|
import date from "../lib/date";
|
|
import { IPostMeta } from "../lib/slug";
|
|
import style from '../styles/recent-posts.module.css';
|
|
|
|
function RecentPosts({ postsMeta }: { postsMeta: IPostMeta[] }) {
|
|
if (!postsMeta.length)
|
|
return <></>;
|
|
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}>
|
|
{date.toRelativeDate(new Date(post.created_at))}
|
|
</span>
|
|
<div className={style.postTitle}>
|
|
<Link href={`/posts/${post.slug}`}>
|
|
{post.title}
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
})}
|
|
</div>
|
|
{
|
|
postsMeta.length > 10 &&
|
|
<div className={style.more}>
|
|
<Link href='/posts' className='h5'>More...</Link>
|
|
</div>
|
|
}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default RecentPosts;
|