Merge branch 'feature/link-outer-page' into develop

This commit is contained in:
tangly
2022-11-17 23:19:18 +08:00
10 changed files with 71 additions and 24 deletions

37
lib/notion/getNotion.js Normal file
View File

@@ -0,0 +1,37 @@
import BLOG from '@/blog.config'
import { idToUuid } from 'notion-utils'
import formatDate from '../formatDate'
import { getPostBlocks } from './getPostBlocks'
import { defaultMapImageUrl } from 'react-notion-x'
export async function getNotion(pageId) {
const blockMap = await getPostBlocks(pageId, 'slug')
if (!blockMap) {
return null
}
const postInfo = blockMap?.block?.[idToUuid(pageId)].value
return {
id: pageId,
type: postInfo,
category: '',
tags: [],
title: postInfo?.properties?.title?.[0],
status: 'Published',
createdTime: formatDate(new Date(postInfo.created_time).toString(), BLOG.LANG),
lastEditedTime: formatDate(new Date(postInfo?.last_edited_time).toString(), BLOG.LANG),
fullWidth: false,
page_cover: getPageCover(postInfo),
date: { start_date: formatDate(new Date(postInfo?.last_edited_time).toString(), BLOG.LANG) },
blockMap
}
}
function getPageCover(postInfo) {
const pageCover = postInfo.format?.page_cover
if (pageCover) {
if (pageCover.startsWith('/')) return 'https://www.notion.so' + pageCover
if (pageCover.startsWith('http')) return defaultMapImageUrl(pageCover, postInfo)
}
}

View File

@@ -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, siteInfo) {
export default 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
@@ -96,5 +96,3 @@ async function getPageProperties(id, block, schema, authToken, tagOptions, siteI
}
}
}
export { getPageProperties as default }

View File

@@ -28,7 +28,7 @@ export async function getPostBlocks(id, from, slice) {
* @param {*} id
* @param {*} retryAttempts
*/
async function getPageWithRetry(id, from, retryAttempts = 3) {
export async function getPageWithRetry(id, from, retryAttempts = 3) {
if (retryAttempts && retryAttempts > 0) {
console.log('[请求API]', `from:${from}`, `id:${id}`, retryAttempts < 3 ? `剩余重试次数:${retryAttempts}` : '')
try {