适配无标签文章
This commit is contained in:
tangly
2021-12-06 20:39:26 +08:00
parent 22c421a0c3
commit 97266b130f
7 changed files with 12 additions and 8 deletions

View File

@@ -3,8 +3,6 @@ import getAllPageIds from './getAllPageIds'
import getPageProperties from './getPageProperties'
import { defaultMapImageUrl } from 'react-notion-x'
import { getNotionPageData } from '@/lib/notion/getNotionData'
import TagItemMini from '@/components/TagItemMini'
import React from 'react'
/**
* 获取所有文章列表
@@ -26,19 +24,19 @@ export async function getAllPosts ({ notionPageData, from, includePage = false }
const tagOptions = notionPageData.tagOptions
const collectionQuery = notionPageData.collectionQuery
// 获取每篇文章信息
const data = []
const pageIds = getAllPageIds(collectionQuery)
for (let i = 0; i < pageIds.length; i++) {
const id = pageIds[i]
const properties = (await getPageProperties(id, pageBlock, schema)) || null
const tagItems = properties?.tags?.map(tag => { return { name: tag, color: tagOptions.find(t => t.value === tag).color } }) || ['默认']
properties.createdTime = new Date(pageBlock[id].value?.created_time).toString()
properties.lastEditedTime = new Date(pageBlock[id].value?.last_edited_time).toString()
properties.fullWidth = pageBlock[id].value?.format?.page_full_width ?? false
properties.page_cover = getPostCover(id, pageBlock) ?? BLOG.defaultImgCover
properties.content = pageBlock[id].value?.content ?? []
properties.tagItems = tagItems
properties.tagItems = properties?.tags?.map(tag => {
return { name: tag, color: tagOptions.find(t => t.value === tag)?.color || 'gray' }
}) || []
data.push(properties)
}