diff --git a/components/LatestPosts.js b/components/LatestPosts.js index 603e6bbd..b5caaf1f 100644 --- a/components/LatestPosts.js +++ b/components/LatestPosts.js @@ -9,15 +9,21 @@ import { useRouter } from 'next/router' * @constructor */ const LatestPosts = ({ posts }) => { - // 按时间排序 - if (posts) { - posts = posts.sort((a, b) => { + // 深拷贝 + 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 - }).slice(0, 5) - } - const router = useRouter() + }) + + // 只取前五 + postsSortByDate = postsSortByDate.slice(0, 5) + + // 获取当前路径 + const currentPath = useRouter().asPath return <>
{
最近更新
- {posts.map(post => { + {postsSortByDate.map(post => { return ( -
+
{formatDateFmt(post.lastEditedTime, 'yyyy/MM/dd')}
diff --git a/components/SearchInput.js b/components/SearchInput.js index df0799a3..6ed58415 100644 --- a/components/SearchInput.js +++ b/components/SearchInput.js @@ -45,7 +45,7 @@ const SearchInput = ({ currentTag, currentSearch }) => { /> { (searchKey && searchKey.length && )} -
{ handleSearch(searchKey) }}>
diff --git a/components/SideBar.js b/components/SideBar.js index 7f3ba827..ba20e64b 100644 --- a/components/SideBar.js +++ b/components/SideBar.js @@ -20,14 +20,6 @@ import DarkModeButton from '@/components/DarkModeButton' * @constructor */ const SideBar = ({ tags, currentTag, post, posts, categories, currentCategory }) => { - // 按时间排序 - if (posts) { - posts = posts.sort((a, b) => { - const dateA = new Date(a?.lastEditedTime || a.createdTime) - const dateB = new Date(b?.lastEditedTime || b.createdTime) - return dateB - dateA - }).slice(0, 5) - } return
-
+
diff --git a/lib/cache/cache_manager.js b/lib/cache/cache_manager.js index 25d76ba0..34b5fff7 100644 --- a/lib/cache/cache_manager.js +++ b/lib/cache/cache_manager.js @@ -1,7 +1,11 @@ import { getCacheFromFile, setCacheToFile } from '@/lib/cache/local_file_cache' import { getCacheFromMemory, setCacheToMemory } from '@/lib/cache/memory_cache' import BLOG from '@/blog.config' - +/** + * 为减少频繁接口请求,notion数据将被缓存 + * @param {*} key + * @returns + */ export async function getDataFromCache (key) { let dataFromCache if (BLOG.isProd) {