diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js index 3f9d2579..c7401030 100644 --- a/lib/notion/getAllPosts.js +++ b/lib/notion/getAllPosts.js @@ -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 diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 43fb139a..3df1db8f 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -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 }) } diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index a08a7572..1fbea148 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -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)