mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-30 15:10:11 +00:00
全文索引功能完善
This commit is contained in:
@@ -23,13 +23,30 @@ function appendText (sourceTextArray, targetObj, key) {
|
||||
return sourceTextArray
|
||||
}
|
||||
const textArray = targetObj[key]
|
||||
const text = textArray ? textArray[0][0] : ''
|
||||
const text = textArray ? getTextContent(textArray) : ''
|
||||
if (text && text !== 'Untitled') {
|
||||
return sourceTextArray.concat(text)
|
||||
}
|
||||
return sourceTextArray
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取层层嵌套的数组
|
||||
* @param {*} textArray
|
||||
* @returns
|
||||
*/
|
||||
function getTextContent (textArray) {
|
||||
if (typeof textArray === 'object') {
|
||||
let result = ''
|
||||
textArray.forEach(textObj => {
|
||||
result = result + getTextContent(textObj)
|
||||
})
|
||||
return result
|
||||
} else if (typeof textArray === 'string') {
|
||||
return textArray
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStaticProps ({ params: { keyword } }) {
|
||||
const {
|
||||
allPosts,
|
||||
@@ -55,9 +72,6 @@ export async function getStaticProps ({ params: { keyword } }) {
|
||||
indexContent = appendText(indexContent, properties, 'caption')
|
||||
})
|
||||
}
|
||||
if (page !== null) {
|
||||
console.log('读取缓存成功', page, indexContent)
|
||||
}
|
||||
post.results = []
|
||||
let hit = false
|
||||
const re = new RegExp(`${keyword}`, 'g')
|
||||
|
||||
Reference in New Issue
Block a user