mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-13 23:16:47 +00:00
feat(getPageContentText): replace custom text extraction with notion-utils
The getTextContent function was removed and replaced with an import from notion-utils, simplifying the text extraction logic for Notion page content. This change removes the custom recursive implementation and uses the standardized utility function instead.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { checkStrIsUuid, isIterable } from '@/lib/utils'
|
||||
import { getTextContent } from 'notion-utils'
|
||||
|
||||
export function getPageContentText(post, pageBlockMap) {
|
||||
/**
|
||||
@@ -24,34 +24,6 @@ export function getPageContentText(post, pageBlockMap) {
|
||||
return ''
|
||||
}
|
||||
|
||||
// todo: 清除更多无用标签
|
||||
const removeTypeFlag = ['a', 'p', '‣']
|
||||
|
||||
/**
|
||||
* 递归获取层层嵌套的数组
|
||||
* @param {*} textArray
|
||||
* @returns string
|
||||
*/
|
||||
function getTextContent(textArray) {
|
||||
if (typeof textArray === 'object' && isIterable(textArray)) {
|
||||
let result = ''
|
||||
for (const textObj of textArray) {
|
||||
if (textArray.length > 1 && removeTypeFlag.includes(textArray[0])) {
|
||||
return result
|
||||
}
|
||||
result = result + getTextContent(textObj)
|
||||
}
|
||||
return result
|
||||
} else if (typeof textArray === 'string') {
|
||||
if (checkStrIsUuid(textArray) && pageBlockMap.block[textArray]) {
|
||||
return getBlockContentText(textArray)
|
||||
} else if (textArray === pageBlockMap.block[postId].value.space_id) {
|
||||
return ''
|
||||
}
|
||||
return textArray
|
||||
}
|
||||
}
|
||||
|
||||
function getTransclusionReference(block) {
|
||||
const result = []
|
||||
const blockPointer = block.format.transclusion_reference_pointer
|
||||
|
||||
Reference in New Issue
Block a user