mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
Merge pull request #987 from tangly1024/fix/article-password
fix/article-password
This commit is contained in:
@@ -4,6 +4,11 @@ import formatDate from '../formatDate'
|
||||
import { getPostBlocks } from './getPostBlocks'
|
||||
import { defaultMapImageUrl } from 'react-notion-x'
|
||||
|
||||
/**
|
||||
* 根据页面ID获取内容
|
||||
* @param {*} pageId
|
||||
* @returns
|
||||
*/
|
||||
export async function getNotion(pageId) {
|
||||
const blockMap = await getPostBlocks(pageId, 'slug')
|
||||
if (!blockMap) {
|
||||
|
||||
@@ -3,6 +3,13 @@ import { NotionAPI } from 'notion-client'
|
||||
import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager'
|
||||
import { deepClone, delay } from '../utils'
|
||||
|
||||
/**
|
||||
* 获取文章内容
|
||||
* @param {*} id
|
||||
* @param {*} from
|
||||
* @param {*} slice
|
||||
* @returns
|
||||
*/
|
||||
export async function getPostBlocks(id, from, slice) {
|
||||
const cacheKey = 'page_block_' + id
|
||||
let pageBlock = await getDataFromCache(cacheKey)
|
||||
@@ -71,6 +78,13 @@ function filterPostBlocks(id, pageBlock, slice) {
|
||||
delete clonePageBlock?.block[i]
|
||||
continue
|
||||
}
|
||||
// 当BlockId等于PageId时移除
|
||||
if (b?.value?.id === id) {
|
||||
// 此block含有敏感信息
|
||||
delete b?.value?.properties
|
||||
continue
|
||||
}
|
||||
|
||||
count++
|
||||
// 处理 c++、c#、汇编等语言名字映射
|
||||
if (b?.value?.type === 'code') {
|
||||
|
||||
@@ -114,25 +114,31 @@ export async function getStaticProps({ params: { slug } }) {
|
||||
}
|
||||
const from = `slug-props-${fullSlug}`
|
||||
const props = await getGlobalNotionData({ from })
|
||||
// 在列表内查找文章
|
||||
props.post = props.allPages.find((p) => {
|
||||
return p.slug === fullSlug || p.id === idToUuid(fullSlug)
|
||||
})
|
||||
|
||||
if (!props.post) {
|
||||
// 处理非列表内文章的内信息
|
||||
if (!props?.post) {
|
||||
const pageId = slug.slice(-1)[0]
|
||||
if (pageId.length < 32) {
|
||||
return { props, revalidate: parseInt(BLOG.NEXT_REVALIDATE_SECOND) }
|
||||
}
|
||||
const post = await getNotion(pageId)
|
||||
if (post) {
|
||||
if (pageId.length >= 32) {
|
||||
const post = await getNotion(pageId)
|
||||
props.post = post
|
||||
} else {
|
||||
return { props, revalidate: parseInt(BLOG.NEXT_REVALIDATE_SECOND) }
|
||||
}
|
||||
} else {
|
||||
props.post.blockMap = await getPostBlocks(props.post.id, 'slug')
|
||||
}
|
||||
|
||||
// 无法获取文章
|
||||
if (!props?.post) {
|
||||
return { props, revalidate: parseInt(BLOG.NEXT_REVALIDATE_SECOND) }
|
||||
}
|
||||
|
||||
// 文章内容加载
|
||||
if (!props?.posts?.blockMap) {
|
||||
props.post.blockMap = await getPostBlocks(props.post.id, from)
|
||||
}
|
||||
|
||||
// 推荐关联文章处理
|
||||
const allPosts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
if (allPosts && allPosts.length > 0) {
|
||||
const index = allPosts.indexOf(props.post)
|
||||
|
||||
Reference in New Issue
Block a user