From cd8954d02a2c3f8b0d3a1b733a100749ac75d837 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Mon, 28 Feb 2022 15:31:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85getLatestPosts=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getNotionData.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 4873cf9c..7b4aebbe 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -37,7 +37,17 @@ export async function getGlobalNotionData ({ const customNav = await getCustomNav({ notionPageData }) const categories = await getAllCategories(allPosts) const tags = await getAllTags({ allPosts, tagOptions, sliceCount: tagsCount }) - // 深拷贝 + const latestPosts = await getLatestPosts({ notionPageData, from, latestPostCount }) + return { allPosts, latestPosts, categories, postCount, customNav, tags } +} + +/** + * 获取最新文章 + * @param {*}} param0 + * @returns + */ +async function getLatestPosts ({ notionPageData, from, latestPostCount }) { + const allPosts = await getAllPosts({ notionPageData, from, pageType: ['Post'] }) let latestPosts = Object.create(allPosts) // 时间排序 latestPosts.sort((a, b) => { @@ -48,14 +58,7 @@ export async function getGlobalNotionData ({ // 只取前五 latestPosts = latestPosts.slice(0, latestPostCount) - return { - allPosts, - latestPosts, - categories, - postCount, - customNav, - tags - } + return latestPosts } /**