diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index dd26937e..62691554 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -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 || {} } diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index c3bfaeff..870071b4 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -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')