From ab375a3cdc6ca77bb13dc3f9467ae797a01e011d Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 3 Nov 2021 16:24:58 +0800 Subject: [PATCH] =?UTF-8?q?feature:=E6=9C=80=E6=96=B0=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E8=B0=83=E6=95=B4=EF=BC=8C=E9=80=82=E9=85=8D?= =?UTF-8?q?=E5=A4=9C=E9=97=B4=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/SideBar.js | 10 +++++----- lib/notion/getAllPosts.js | 4 +++- lib/notion/getPostBlocks.js | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/SideBar.js b/components/SideBar.js index 562525a4..8838b651 100644 --- a/components/SideBar.js +++ b/components/SideBar.js @@ -9,8 +9,8 @@ const SideBar = ({ tags, currentTag, post, posts }) => { // 按时间排序 if (posts) { posts = posts.sort((a, b) => { - const dateA = new Date(a?.date?.start_date || a.createdTime) - const dateB = new Date(b?.date?.start_date || b.createdTime) + const dateA = new Date(a?.lastEditedTime || a.createdTime) + const dateB = new Date(b?.lastEditedTime || b.createdTime) return dateB - dateA }).slice(0, 5) } @@ -31,17 +31,17 @@ const SideBar = ({ tags, currentTag, post, posts }) => {
-
最新文章
+
最近更新
{posts.map(post => { return ( -
+
{post.title}
-
{post.title}
+
{post.title}
) diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js index 3deff3cd..02aaab2a 100644 --- a/lib/notion/getAllPosts.js +++ b/lib/notion/getAllPosts.js @@ -48,10 +48,12 @@ async function getPostsFromNotionAPI ({ from }) { for (let i = 0; i < pageIds.length; i++) { const id = pageIds[i] const properties = (await getPageProperties(id, block, schema)) || null - // Add fullwidth, createdtime to properties properties.createdTime = new Date( block[id].value?.created_time ).toString() + properties.lastEditedTime = new Date( + block[id].value?.last_edited_time + ).toString() properties.fullWidth = block[id].value?.format?.page_full_width ?? false properties.page_cover = getPostCover(id, block, pageRecordMap) ?? getContentFirstImage(id, block, pageRecordMap) properties.content = block[id].value?.content ?? [] diff --git a/lib/notion/getPostBlocks.js b/lib/notion/getPostBlocks.js index c9cbfa50..e032a329 100644 --- a/lib/notion/getPostBlocks.js +++ b/lib/notion/getPostBlocks.js @@ -1,6 +1,7 @@ import BLOG from '@/blog.config' import { NotionAPI } from 'notion-client' import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager' +import { useRouter } from 'next/router' export async function getPostBlocks (id, from) { let pageBlock = await getDataFromCache('page_block_' + id)