完善获取文章列表

This commit is contained in:
tangly1024
2022-05-09 13:52:44 +08:00
parent d200420c31
commit adac140892
4 changed files with 41 additions and 25 deletions

View File

@@ -21,22 +21,22 @@ export async function getAllPosts({ notionPageData, from, pageType }) {
return []
}
const pageBlock = notionPageData.block
const schema = notionPageData.schema
const tagOptions = notionPageData.tags
const collectionQuery = notionPageData.collectionQuery
const { block, schema, tagOptions, collectionQuery, collectionId, collectionView, viewIds } = notionPageData
const data = []
const pageIds = getAllPageIds(collectionQuery)
const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds)
for (let i = 0; i < pageIds.length; i++) {
const id = pageIds[i]
const properties = (await getPageProperties(id, pageBlock, schema)) || null
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(pageBlock[id].value?.created_time).toString(), BLOG.LANG)
properties.lastEditedTime = formatDate(new Date(pageBlock[id].value?.last_edited_time).toString(), BLOG.LANG)
properties.fullWidth = pageBlock[id].value?.format?.page_full_width ?? false
properties.page_cover = getPostCover(id, pageBlock) ?? null
properties.content = pageBlock[id].value?.content ?? []
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' }
}) || []