hotfix: sort by date

This commit is contained in:
tangly1024
2023-06-29 23:26:06 +08:00
parent 11035f2cd7
commit 8103e23aac
3 changed files with 5 additions and 6 deletions

View File

@@ -45,9 +45,7 @@ export async function getAllPosts({ notionPageData, from, pageType }) {
// Sort by date
if (BLOG.POSTS_SORT_BY === 'date') {
posts.sort((a, b) => {
const dateA = new Date(a?.publishTime || a.createdTime)
const dateB = new Date(b?.publishTime || b.createdTime)
return dateB - dateA
return b?.sortDate - a?.sortDate
})
}
return posts

View File

@@ -48,8 +48,8 @@ function getLatestPosts({ allPages, from, latestPostCount }) {
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
const latestPosts = Object.create(allPosts).sort((a, b) => {
const dateA = new Date(a?.lastEditedTime || a?.createdTime || a?.publishTime)
const dateB = new Date(b?.lastEditedTime || b?.createdTime || b?.publishTime)
const dateA = new Date(a?.lastEditedTime || a?.sortDate)
const dateB = new Date(b?.lastEditedTime || b?.sortDate)
return dateB - dateA
})
return latestPosts.slice(0, latestPostCount)
@@ -298,7 +298,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
// Sort by date
if (BLOG.POSTS_SORT_BY === 'date') {
allPages.sort((a, b) => {
return b.publishTime - a.publishTime
return b?.sortDate - a?.sortDate
})
}

View File

@@ -93,6 +93,7 @@ export default async function getPageProperties(id, block, schema, authToken, ta
}
}
properties.sortDate = value?.date?.start_date || value.created_time
properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG)
properties.publishTime = value?.date?.start_date ? formatDate(new Date(value?.date?.start_date).toString, BLOG.LANG) : properties.createdTime
properties.lastEditedTime = formatDate(new Date(value?.last_edited_time).toString(), BLOG.LANG)