封装getLatestPosts方法

This commit is contained in:
tangly1024
2022-02-28 15:31:24 +08:00
parent d0dece5539
commit cd8954d02a

View File

@@ -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
}
/**