获取外部Notion页面

This commit is contained in:
tangly
2022-11-16 22:21:57 +08:00
parent 12babbdbca
commit 1e56ced00d
8 changed files with 59 additions and 17 deletions

View File

@@ -7,6 +7,7 @@ import React from 'react'
import { idToUuid } from 'notion-utils'
import Router from 'next/router'
import { isBrowser } from '@/lib/utils'
import { getNotion } from '@/lib/notion/getNotion'
/**
* 根据notion的slug访问页面
@@ -26,11 +27,11 @@ const Slug = props => {
const article = document.getElementById('container')
if (!article) {
router.push('/404').then(() => {
// console.warn('找不到页面', router.asPath)
console.warn('找不到页面', router.asPath)
})
}
}
}, 10000)
}, 20 * 1000)
const meta = { title: `${props?.siteInfo?.title || BLOG.TITLE} | loading`, image: siteInfo?.pageCover }
return <ThemeComponents.LayoutSlug {...props} showArticleInfo={true} meta={meta} />
}
@@ -62,7 +63,7 @@ const Slug = props => {
const meta = {
title: `${post?.title} | ${siteInfo?.title}`,
description: post?.summary,
type: post.type,
type: post?.type,
slug: post?.slug,
image: post?.page_cover,
category: post?.category?.[0],
@@ -102,11 +103,17 @@ export async function getStaticProps({ params: { slug } }) {
props.post = props.allPages.find((p) => {
return p.slug === fullSlug || p.id === idToUuid(fullSlug)
})
if (!props.post) {
console.warn('无效地址', fullSlug)
return { props, revalidate: 1 }
const post = await getNotion(slug.slice(-1)[0])
if (post) {
props.post = post
} else {
return { props, revalidate: 1 }
}
} else {
props.post.blockMap = await getPostBlocks(props.post.id, 'slug')
}
props.post.blockMap = await getPostBlocks(props.post.id, 'slug')
const allPosts = props.allPages.filter(page => page.type === 'Post')
const index = allPosts.indexOf(props.post)
@@ -134,7 +141,7 @@ export async function getStaticProps({ params: { slug } }) {
function getRecommendPost(post, allPosts, count = 6) {
let recommendPosts = []
const postIds = []
const currentTags = post.tags || []
const currentTags = post?.tags || []
for (let i = 0; i < allPosts.length; i++) {
const p = allPosts[i]
if (p.id === post.id || p.type.indexOf('Post') < 0) {