mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-17 15:09:31 +00:00
Merge branch 'feature/link-outer-page' into develop
This commit is contained in:
37
lib/notion/getNotion.js
Normal file
37
lib/notion/getNotion.js
Normal 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)
|
||||
}
|
||||
}
|
||||
@@ -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 }
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user