mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-30 23:16:52 +00:00
封装PageProperties 修复文章排序
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import BLOG from '@/blog.config'
|
||||
import getAllPageIds from './getAllPageIds'
|
||||
import getPageProperties from './getPageProperties'
|
||||
import { defaultMapImageUrl } from 'react-notion-x'
|
||||
import formatDate from '@/lib/formatDate'
|
||||
import { getNotionPageData } from '@/lib/notion/getNotionData'
|
||||
import { delCacheData } from '@/lib/cache/cache_manager'
|
||||
|
||||
@@ -26,21 +24,11 @@ export async function getAllPosts({ notionPageData, from, pageType }) {
|
||||
const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds)
|
||||
for (let i = 0; i < pageIds.length; i++) {
|
||||
const id = pageIds[i]
|
||||
const properties = (await getPageProperties(id, block, schema)) || null
|
||||
const value = block[id]?.value
|
||||
if (!value) {
|
||||
continue
|
||||
}
|
||||
properties.slug = properties.slug ?? properties.id
|
||||
properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG)
|
||||
properties.lastEditedTime = formatDate(new Date(value?.last_edited_time).toString(), BLOG.LANG)
|
||||
properties.fullWidth = value.format?.page_full_width ?? false
|
||||
properties.page_cover = getPostCover(id, block) ?? null
|
||||
properties.content = value.content ?? []
|
||||
properties.tagItems = properties?.tags?.map(tag => {
|
||||
return { name: tag, color: tagOptions.find(t => t.value === tag)?.color || 'gray' }
|
||||
}) || []
|
||||
delete properties.content
|
||||
const properties = (await getPageProperties(id, block, schema, tagOptions)) || null
|
||||
data.push(properties)
|
||||
}
|
||||
|
||||
@@ -64,12 +52,3 @@ export async function getAllPosts({ notionPageData, from, pageType }) {
|
||||
}
|
||||
return posts
|
||||
}
|
||||
|
||||
// 从Block获取封面图;优先取PageCover,否则取内容图片
|
||||
function getPostCover(id, block) {
|
||||
const pageCover = block[id].value?.format?.page_cover
|
||||
if (pageCover) {
|
||||
if (pageCover.startsWith('/')) return 'https://www.notion.so' + pageCover
|
||||
if (pageCover.startsWith('http')) return defaultMapImageUrl(pageCover, block[id].value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user