import Link from 'next/link' import BLOG from '@/blog.config' import { formatDateFmt } from '@/lib/formatDate' import { useRouter } from 'next/router' /** * 最新文章列表 * @param posts * @constructor */ const LatestPosts = ({ posts }) => { // 深拷贝 let postsSortByDate = Object.create(posts) // 时间排序 postsSortByDate.sort((a, b) => { const dateA = new Date(a?.lastEditedTime || a.createdTime) const dateB = new Date(b?.lastEditedTime || b.createdTime) return dateB - dateA }) // 只取前五 postsSortByDate = postsSortByDate.slice(0, 5) // 获取当前路径 const currentPath = useRouter().asPath return <>
最近更新
{postsSortByDate.map(post => { return (
{formatDateFmt(post.lastEditedTime, 'yyyy/MM/dd')}
{post.title}
) })}
} export default LatestPosts