fix page-cover-missing

This commit is contained in:
tangly1024
2024-01-30 22:33:05 +08:00
parent d869d5c273
commit ad24ea1f48
3 changed files with 12 additions and 4 deletions

View File

@@ -273,10 +273,15 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
const viewIds = rawMetadata?.view_ids
const collectionData = []
const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds)
if (pageIds?.length === 0) {
console.error('获取到的文章列表为空请检查notion模板', collectionQuery, collection, collectionView, viewIds, pageRecordMap)
} else {
console.log('有效Page数量', pageIds?.length)
}
// 获取每篇文章基础数据
for (let i = 0; i < pageIds.length; i++) {
const id = pageIds[i]
const value = block[id]?.value
@@ -291,7 +296,8 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
}
continue
}
const properties = (await getPageProperties(id, block[id].value, schema, null, getTagOptions(schema))) || null
const properties = (await getPageProperties(id, value, schema, null, getTagOptions(schema))) || null
if (properties) {
collectionData.push(properties)
}

View File

@@ -90,9 +90,10 @@ export default async function getPageProperties(id, value, schema, authToken, ta
properties.lastEditedDate = new Date(value?.last_edited_time)
properties.lastEditedDay = formatDate(new Date(value?.last_edited_time), BLOG.LANG)
properties.fullWidth = value.format?.page_full_width ?? false
properties.pageIcon = mapImgUrl(value.value?.format?.page_icon, value.value) ?? ''
properties.pageCover = mapImgUrl(value.value?.format?.page_cover, value.value) ?? ''
properties.pageCoverThumbnail = mapImgUrl(value.value?.format?.page_cover, value.value, 'block', 'pageCoverThumbnail') ?? ''
properties.pageIcon = mapImgUrl(value?.format?.page_icon, value) ?? ''
properties.pageCover = mapImgUrl(value?.format?.page_cover, value) ?? ''
properties.pageCoverThumbnail = mapImgUrl(value?.format?.page_cover, value, 'block', 'pageCoverThumbnail') ?? ''
properties.content = value.content ?? []
properties.tagItems = properties?.tags?.map(tag => {
return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' }

View File

@@ -61,6 +61,7 @@ export async function getPageWithRetry(id, from, retryAttempts = 3) {
const authToken = BLOG.NOTION_ACCESS_TOKEN || null
const api = new NotionAPI({ authToken, userTimeZone: Intl.DateTimeFormat().resolvedOptions().timeZone })
const pageData = await api.getPage(id)
// console.log('stringfy', JSON.stringify(pageData))
console.info('[响应成功]:', `from:${from}`)
return pageData
} catch (e) {