mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-18 15:09:34 +00:00
调整文章日期显示
This commit is contained in:
@@ -45,8 +45,8 @@ 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?.date?.start_date || a.createdTime)
|
||||
const dateB = new Date(b?.date?.start_date || b.createdTime)
|
||||
const dateA = new Date(a?.publishTime || a.createdTime)
|
||||
const dateB = new Date(b?.publishTime || b.createdTime)
|
||||
return dateB - dateA
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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?.date?.start_date)
|
||||
const dateB = new Date(b?.lastEditedTime || b?.createdTime || b?.date?.start_date)
|
||||
const dateA = new Date(a?.lastEditedTime || a?.createdTime || a?.publishTime)
|
||||
const dateB = new Date(b?.lastEditedTime || b?.createdTime || b?.publishTime)
|
||||
return dateB - dateA
|
||||
})
|
||||
return latestPosts.slice(0, latestPostCount)
|
||||
@@ -298,9 +298,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
|
||||
// Sort by date
|
||||
if (BLOG.POSTS_SORT_BY === 'date') {
|
||||
allPages.sort((a, b) => {
|
||||
const dateA = new Date(a?.date?.start_date || a.createdTime)
|
||||
const dateB = new Date(b?.date?.start_date || b.createdTime)
|
||||
return dateB - dateA
|
||||
return b.publishTime - a.publishTime
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -94,15 +94,14 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
||||
}
|
||||
|
||||
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)
|
||||
properties.fullWidth = value.format?.page_full_width ?? false
|
||||
properties.pageIcon = mapImgUrl(block[id].value?.format?.page_icon, block[id].value) ?? ''
|
||||
properties.pageCover = mapImgUrl(block[id].value?.format?.page_cover, block[id].value) ?? ''
|
||||
properties.pageCoverThumbnail = mapImgUrl(block[id].value?.format?.page_cover, block[id].value, 'block', 'pageCoverThumbnail') ?? ''
|
||||
properties.content = value.content ?? []
|
||||
properties.password = properties.password
|
||||
? md5(properties.slug + properties.password)
|
||||
: ''
|
||||
properties.password = properties.password ? md5(properties.slug + properties.password) : ''
|
||||
properties.tagItems = properties?.tags?.map(tag => {
|
||||
return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' }
|
||||
}) || []
|
||||
@@ -110,6 +109,9 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
||||
return properties
|
||||
}
|
||||
|
||||
/**
|
||||
* 映射用户自定义表头
|
||||
*/
|
||||
function mapProperties(properties) {
|
||||
if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_post) {
|
||||
properties.type = 'Post'
|
||||
@@ -132,14 +134,14 @@ function generateCustomizeUrl(postProperties) {
|
||||
let fullSlug = ''
|
||||
const allSlugPatterns = BLOG.POST_URL_PREFIX.split('/')
|
||||
allSlugPatterns.forEach((pattern, idx) => {
|
||||
if (pattern === '%year%' && postProperties?.date?.start_date) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.date?.start_date)
|
||||
if (pattern === '%year%' && postProperties?.publishTime) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.publishTime)
|
||||
fullSlug += formatPostCreatedDate.getUTCFullYear()
|
||||
} else if (pattern === '%month%' && postProperties?.date?.start_date) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.date?.start_date)
|
||||
} else if (pattern === '%month%' && postProperties?.publishTime) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.publishTime)
|
||||
fullSlug += String(formatPostCreatedDate.getUTCMonth() + 1).padStart(2, 0)
|
||||
} else if (pattern === '%day%' && postProperties?.date?.start_date) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.date?.start_date)
|
||||
} else if (pattern === '%day%' && postProperties?.publishTime) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.publishTime)
|
||||
fullSlug += String(formatPostCreatedDate.getUTCDate()).padStart(2, 0)
|
||||
} else if (pattern === '%slug%') {
|
||||
fullSlug += (postProperties.slug ?? postProperties.id)
|
||||
|
||||
@@ -46,7 +46,7 @@ export async function generateRss(posts) {
|
||||
link: `${BLOG.LINK}/${post.slug}`,
|
||||
description: post.summary,
|
||||
content: await createFeedContent(post),
|
||||
date: new Date(post?.date?.start_date || post?.createdTime)
|
||||
date: new Date(post?.publishTime || post?.createdTime)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export async function generateSitemapXml({ allPages }) {
|
||||
allPages?.forEach(post => {
|
||||
urls.push({
|
||||
loc: `${BLOG.LINK}/${post.slug}`,
|
||||
lastmod: new Date(post?.date?.start_date || post?.createdTime).toISOString().split('T')[0],
|
||||
lastmod: new Date(post?.publishTime || post?.createdTime).toISOString().split('T')[0],
|
||||
changefreq: 'daily'
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user