封装PageProperties 修复文章排序

This commit is contained in:
tangly1024
2022-05-09 16:05:36 +08:00
parent 7b9ee80daa
commit ce046bff22
3 changed files with 33 additions and 27 deletions

View File

@@ -49,13 +49,14 @@ export async function getGlobalNotionData({
*/
function getLatestPosts({ allPosts, from, latestPostCount }) {
const latestPosts = Object.create(allPosts).sort((a, b) => {
console.log('排序过程', a, b)
const dateA = new Date(a?.lastEditedTime || a?.createdTime || a?.date?.start_date)
const dateB = new Date(b?.lastEditedTime || b?.createdTime || b?.date?.start_date)
// const dateA = new Date(a.date?.start_date)
// const dateB = new Date(b.date?.start_date)
return dateB - dateA
})
console.log('排序结果', latestPosts)
return latestPosts.slice(0, latestPostCount)
}
@@ -225,9 +226,11 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
}
for (let i = 0; i < pageIds.length; i++) {
const id = pageIds[i]
const properties = (await getPageProperties(id, block, schema)) || null
properties.slug = properties.slug ?? properties.id
delete properties.content
const value = block[id]?.value
if (!value) {
continue
}
const properties = (await getPageProperties(id, block, schema, tagOptions)) || null
data.push(properties)
}