From 46495f9fe6f410f9bbdc1bf8e3571876cc68eae4 Mon Sep 17 00:00:00 2001 From: tangly Date: Sat, 6 Nov 2021 11:37:20 +0800 Subject: [PATCH] =?UTF-8?q?bugFix:=20=E6=9C=80=E6=96=B0=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=EF=BC=9B=20=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E5=BA=95=E8=BE=B9=E6=A0=B7=E5=BC=8F=EF=BC=9B=20=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E8=83=8C=E6=99=AF=E8=89=B2=E9=AB=98=E5=BA=A6=EF=BC=9B?= =?UTF-8?q?=20=E5=A4=9C=E9=97=B4=E6=A8=A1=E5=BC=8F=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=EF=BC=9B=20=E7=A7=BB=E5=8A=A8=E7=AB=AF?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E6=82=AC=E6=B5=AEDarkmode=E6=8C=89=E9=92=AE?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/LatestPosts.js | 22 ++++++++++++++-------- components/SearchInput.js | 2 +- components/SideBar.js | 8 -------- components/Toc.js | 4 ++-- components/TopNav.js | 2 +- layouts/BaseLayout.js | 2 +- lib/cache/cache_manager.js | 6 +++++- 7 files changed, 24 insertions(+), 22 deletions(-) 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) {