From 11f34d47486ecaf155ee8955b39fe05dc781db33 Mon Sep 17 00:00:00 2001 From: EFL Date: Sun, 14 Jul 2024 11:00:33 +0800 Subject: [PATCH] fix2 --- lib/notion/getPostBlocks.js | 105 ++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/lib/notion/getPostBlocks.js b/lib/notion/getPostBlocks.js index 54dde7ff..3ba77729 100644 --- a/lib/notion/getPostBlocks.js +++ b/lib/notion/getPostBlocks.js @@ -84,63 +84,62 @@ function filterPostBlocks(id, blockMap, slice) { const blocksToProcess = Object.keys(clonePageBlock?.block || {}) // 循环遍历文档的每个block - for (const i in clonePageBlock?.block) { - for (let i = 0; i < blocksToProcess.length; i++) { - const blockId = blocksToProcess[i] - const b = clonePageBlock?.block[blockId] - - if (slice && slice > 0 && count > slice) { - delete clonePageBlock?.block[blockId] - continue + for (let i = 0; i < blocksToProcess.length; i++) { + const blockId = blocksToProcess[i] + const b = clonePageBlock?.block[blockId] + + if (slice && slice > 0 && count > slice) { + delete clonePageBlock?.block[blockId] + continue + } + + if (b?.value?.id === id) { + delete b?.value?.properties + continue + } + + count++ + + if (b?.value?.type === 'sync_block' && b?.value?.children) { + const childBlocks = b.value.children + // Remove the sync block + delete clonePageBlock.block[blockId] + // Insert child blocks in place of the sync block + childBlocks.forEach((childBlock, index) => { + const newBlockId = `${blockId}_child_${index}` + clonePageBlock.block[newBlockId] = childBlock + blocksToProcess.splice(i + index + 1, 0, newBlockId) + }) + // Adjust the loop counter to process the newly inserted blocks + i-- + continue + } + + if (b?.value?.type === 'code') { + if (b?.value?.properties?.language?.[0][0] === 'C++') { + b.value.properties.language[0][0] = 'cpp' } - - if (b?.value?.id === id) { - delete b?.value?.properties - continue + if (b?.value?.properties?.language?.[0][0] === 'C#') { + b.value.properties.language[0][0] = 'csharp' } - - count++ - - if (b?.value?.type === 'sync_block' && b?.value?.children) { - const childBlocks = b.value.children - // Remove the sync block - delete clonePageBlock.block[blockId] - // Insert child blocks in place of the sync block - childBlocks.forEach((childBlock, index) => { - const newBlockId = `${blockId}_child_${index}` - clonePageBlock.block[newBlockId] = childBlock - blocksToProcess.splice(i + index + 1, 0, newBlockId) - }) - // Adjust the loop counter to process the newly inserted blocks - i-- - continue - } - - if (b?.value?.type === 'code') { - if (b?.value?.properties?.language?.[0][0] === 'C++') { - b.value.properties.language[0][0] = 'cpp' - } - if (b?.value?.properties?.language?.[0][0] === 'C#') { - b.value.properties.language[0][0] = 'csharp' - } - if (b?.value?.properties?.language?.[0][0] === 'Assembly') { - b.value.properties.language[0][0] = 'asm6502' - } - } - - if ( - (b?.value?.type === 'file' || - b?.value?.type === 'pdf' || - b?.value?.type === 'video' || - b?.value?.type === 'audio') && - b?.value?.properties?.source?.[0][0] && - b?.value?.properties?.source?.[0][0].indexOf('amazonaws.com') > 0 - ) { - const oldUrl = b?.value?.properties?.source?.[0][0] - const newUrl = `https://notion.so/signed/${encodeURIComponent(oldUrl)}?table=block&id=${b?.value?.id}` - b.value.properties.source[0][0] = newUrl + if (b?.value?.properties?.language?.[0][0] === 'Assembly') { + b.value.properties.language[0][0] = 'asm6502' } } + + if ( + (b?.value?.type === 'file' || + b?.value?.type === 'pdf' || + b?.value?.type === 'video' || + b?.value?.type === 'audio') && + b?.value?.properties?.source?.[0][0] && + b?.value?.properties?.source?.[0][0].indexOf('amazonaws.com') > 0 + ) { + const oldUrl = b?.value?.properties?.source?.[0][0] + const newUrl = `https://notion.so/signed/${encodeURIComponent(oldUrl)}?table=block&id=${b?.value?.id}` + b.value.properties.source[0][0] = newUrl + } +} // 去掉不用的字段 if (id === BLOG.NOTION_PAGE_ID) {