Merge pull request #2592 from RayGicEFL/main

🪲 fix: unable to load synced blocks
This commit is contained in:
tangly1024
2024-07-24 11:00:35 +08:00
committed by GitHub
5 changed files with 61 additions and 39 deletions

View File

@@ -22,6 +22,7 @@ export default {
COMMON: { COMMON: {
THEME: 'Theme', THEME: 'Theme',
ARTICLE_LIST: 'Article List', ARTICLE_LIST: 'Article List',
RECOMMEND_POSTS: 'Recommend Posts',
MORE: 'More', MORE: 'More',
NO_MORE: 'No More', NO_MORE: 'No More',
LATEST_POSTS: 'Latest posts', LATEST_POSTS: 'Latest posts',

View File

@@ -22,6 +22,7 @@ export default {
COMMON: { COMMON: {
THEME: 'Theme', THEME: 'Theme',
ARTICLE_LIST: '文章列表', ARTICLE_LIST: '文章列表',
RECOMMEND_POSTS: '推荐文章',
MORE: '更多', MORE: '更多',
NO_MORE: '没有更多了', NO_MORE: '没有更多了',
LATEST_POSTS: '最新发布', LATEST_POSTS: '最新发布',

View File

@@ -81,14 +81,18 @@ export async function getPageWithRetry(id, from, retryAttempts = 3) {
function filterPostBlocks(id, blockMap, slice) { function filterPostBlocks(id, blockMap, slice) {
const clonePageBlock = deepClone(blockMap) const clonePageBlock = deepClone(blockMap)
let count = 0 let count = 0
const blocksToProcess = Object.keys(clonePageBlock?.block || {})
// 循环遍历文档的每个block // 循环遍历文档的每个block
for (const i in clonePageBlock?.block) { for (let i = 0; i < blocksToProcess.length; i++) {
const b = clonePageBlock?.block[i] const blockId = blocksToProcess[i]
const b = clonePageBlock?.block[blockId]
if (slice && slice > 0 && count > slice) { if (slice && slice > 0 && count > slice) {
delete clonePageBlock?.block[i] delete clonePageBlock?.block[blockId]
continue continue
} }
// 当BlockId等于PageId时移除 // 当BlockId等于PageId时移除
if (b?.value?.id === id) { if (b?.value?.id === id) {
// 此block含有敏感信息 // 此block含有敏感信息
@@ -97,6 +101,22 @@ function filterPostBlocks(id, blockMap, slice) {
} }
count++ count++
if (b?.value?.type === 'sync_block' && b?.value?.children) {
const childBlocks = b.value.children
// 移除同步块
delete clonePageBlock.block[blockId]
// 用子块替代同步块
childBlocks.forEach((childBlock, index) => {
const newBlockId = `${blockId}_child_${index}`
clonePageBlock.block[newBlockId] = childBlock
blocksToProcess.splice(i + index + 1, 0, newBlockId)
})
// 重新处理新加入的子块
i--
continue
}
// 处理 c++、c#、汇编等语言名字映射 // 处理 c++、c#、汇编等语言名字映射
if (b?.value?.type === 'code') { if (b?.value?.type === 'code') {
if (b?.value?.properties?.language?.[0][0] === 'C++') { if (b?.value?.properties?.language?.[0][0] === 'C++') {
@@ -123,7 +143,7 @@ function filterPostBlocks(id, blockMap, slice) {
const newUrl = `https://notion.so/signed/${encodeURIComponent(oldUrl)}?table=block&id=${b?.value?.id}` const newUrl = `https://notion.so/signed/${encodeURIComponent(oldUrl)}?table=block&id=${b?.value?.id}`
b.value.properties.source[0][0] = newUrl b.value.properties.source[0][0] = newUrl
} }
} }
// 去掉不用的字段 // 去掉不用的字段
if (id === BLOG.NOTION_PAGE_ID) { if (id === BLOG.NOTION_PAGE_ID) {

View File

@@ -30,7 +30,7 @@ const BlogPostCard = ({ index, post, showSummary, siteInfo }) => {
{/* 图片封面 */} {/* 图片封面 */}
{showPageCover && ( {showPageCover && (
<Link href={post?.href} passHref legacyBehavior> <Link href={post?.href} passHref legacyBehavior>
<div className='w-full md:w-5/12 2xl:w-full overflow-hidden'> <div className='w-full md:w-5/12 2xl:w-full overflow-hidden cursor-pointer select-none'>
<LazyImage <LazyImage
priority={index === 0} priority={index === 0}
src={post?.pageCoverThumbnail} src={post?.pageCoverThumbnail}

View File

@@ -383,7 +383,7 @@ function TodayCard({ cRef, siteInfo }) {
} }
/> />
<div id='more' className='select-none'> <div id='more' className='select-none'>
{locale.COMMON.MORE} {locale.COMMON.RECOMMEND_POSTS}
</div> </div>
</div> </div>
</div> </div>