mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-30 23:16:52 +00:00
feat(getPageContentText): add null checks for block references
- Add validation for transclusion reference pointer existence - Return empty string when block is not found - Prevent potential errors from undefined block references
This commit is contained in:
@@ -56,7 +56,7 @@ export function getPageContentText(post, pageBlockMap) {
|
|||||||
const result = []
|
const result = []
|
||||||
const blockPointer = block.format.transclusion_reference_pointer
|
const blockPointer = block.format.transclusion_reference_pointer
|
||||||
const blockPointerId = blockPointer.id
|
const blockPointerId = blockPointer.id
|
||||||
if (blockPointer) {
|
if (blockPointer && pageBlockMap.block[blockPointerId].value) {
|
||||||
const blockContentList = pageBlockMap.block[blockPointerId].value.content
|
const blockContentList = pageBlockMap.block[blockPointerId].value.content
|
||||||
for (const blockContent of blockContentList) {
|
for (const blockContent of blockContentList) {
|
||||||
result.push(getBlockContentText(blockContent))
|
result.push(getBlockContentText(blockContent))
|
||||||
@@ -67,6 +67,9 @@ export function getPageContentText(post, pageBlockMap) {
|
|||||||
|
|
||||||
function getBlockContentText(id) {
|
function getBlockContentText(id) {
|
||||||
const block = pageBlockMap?.block[id].value
|
const block = pageBlockMap?.block[id].value
|
||||||
|
if (!block) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
const blockType = block.type
|
const blockType = block.type
|
||||||
// todo: 处理更多类型
|
// todo: 处理更多类型
|
||||||
switch (blockType) {
|
switch (blockType) {
|
||||||
|
|||||||
Reference in New Issue
Block a user