Skip to content

Commit

Permalink
空白封面
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed May 19, 2022
1 parent a3f2494 commit 1aa215b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/notion/getAllPosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function getAllPosts({ notionPageData, from, pageType }) {
if (!value) {
continue
}
const properties = (await getPageProperties(id, block, schema, tagOptions)) || null
const properties = (await getPageProperties(id, block, schema, null, tagOptions, notionPageData.siteInfo)) || null
data.push(properties)
}

Expand Down
10 changes: 6 additions & 4 deletions lib/notion/getNotionData.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export async function getGlobalNotionData({
}) {
// 获取Notion数据
const notionPageData = deepClone(await getNotionPageData({ pageId, from }))
notionPageData.siteInfo = getBlogInfo({ collection: notionPageData?.collection, block: notionPageData?.block })

// 获取文章列表
notionPageData.allPosts = await getAllPosts({ notionPageData, from, pageType })
delete notionPageData.block
Expand Down Expand Up @@ -239,6 +237,7 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
const viewIds = rawMetadata?.view_ids
const data = []
const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds)
const siteInfo = getBlogInfo({ collection, block })
if (pageIds?.length === 0) {
console.error('获取到的文章列表为空,请检查notion模板', collectionQuery, collection, pageRecordMap)
}
Expand All @@ -248,8 +247,10 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
if (!value) {
continue
}
const properties = (await getPageProperties(id, block, schema, tagOptions)) || null
data.push(properties)
const properties = (await getPageProperties(id, block, schema, null, tagOptions, siteInfo)) || null
if (properties) {
data.push(properties)
}
}

const allPage = data.filter(post => {
Expand All @@ -266,6 +267,7 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
const latestPosts = getLatestPosts({ allPosts, from, latestPostCount: 5 })

return {
siteInfo,
collection,
collectionQuery,
collectionId,
Expand Down
4 changes: 2 additions & 2 deletions lib/notion/getPageProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import BLOG from '@/blog.config'
import formatDate from '../formatDate'
import { defaultMapImageUrl } from 'react-notion-x'

async function getPageProperties(id, block, schema, authToken, tagOptions) {
async function getPageProperties(id, block, schema, authToken, tagOptions, siteInfo) {
const rawProperties = Object.entries(block?.[id]?.value?.properties || [])
const excludeProperties = ['date', 'select', 'multi_select', 'person']
const value = block[id]?.value
Expand Down Expand Up @@ -63,7 +63,7 @@ async function getPageProperties(id, block, schema, authToken, tagOptions) {
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.page_cover = getPostCover(id, block) ?? siteInfo?.pageCover
properties.content = value.content ?? []
properties.tagItems = properties?.tags?.map(tag => {
return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' }
Expand Down

0 comments on commit 1aa215b

Please sign in to comment.