Merge pull request #74 from tangly1024/feature-search

iterater问题修复
This commit is contained in:
tangly1024
2022-03-02 16:35:20 +08:00
committed by GitHub
2 changed files with 11 additions and 3 deletions

View File

@@ -109,11 +109,13 @@ async function getCustomNav ({ notionPageData }) {
* @returns {undefined}
*/
function getTagOptions (schema) {
if (!schema) return {}
const tagSchema = Object.values(schema).find(e => e.name === 'tags')
return tagSchema?.options || {}
}
function getCategoryOptions (schema) {
if (!schema) return {}
const categorySchema = Object.values(schema).find(e => e.name === 'category')
return categorySchema?.options || {}
}

View File

@@ -29,7 +29,7 @@ function appendText (sourceTextArray, targetObj, key) {
* @returns
*/
function getTextContent (textArray) {
if (typeof textArray === 'object') {
if (typeof textArray === 'object' && isIterable(textArray)) {
let result = ''
for (const textObj of textArray) {
result = result + getTextContent(textObj)
@@ -40,6 +40,13 @@ function getTextContent (textArray) {
}
}
/**
* 对象是否可以遍历
* @param {*} obj
* @returns
*/
const isIterable = obj => obj != null && typeof obj[Symbol.iterator] === 'function'
export async function getServerSideProps ({ params: { keyword } }) {
const {
allPosts,
@@ -67,8 +74,7 @@ export async function getServerSideProps ({ params: { keyword } }) {
indexContent = appendText(indexContent, properties, 'caption')
})
}
console.log('搜索是否命中缓存', page !== null, indexContent)
// console.log('搜索是否命中缓存', page !== null, indexContent)
post.results = []
let hitCount = 0
const re = new RegExp(`${keyword}`, 'gim')