mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-03 15:10:19 +00:00
获取外部Notion页面
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user