diff --git a/components/Comment.js b/components/Comment.js index 772a3776..075b6ba6 100644 --- a/components/Comment.js +++ b/components/Comment.js @@ -25,6 +25,10 @@ const Comment = ({ frontMatter }) => { return (
+ {BLOG.COMMENT_UTTERRANCES_REPO && (
+ +
)} + {BLOG.COMMENT_CUSDIS_APP_ID && (
{ />
)} - {BLOG.COMMENT_UTTERRANCES_REPO && (
- -
)} - {BLOG.COMMENT_GITALK_CLIENT_ID && (
{
{children.map((item, index) => { - return
- {item} + return
+ {currentTab === index && item}
})}
diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 01f3a46b..3e74b996 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -63,7 +63,9 @@ export async function getStaticProps ({ params: { keyword } }) { const page = await getDataFromCache(cacheKey) const tagContent = post.tags ? post.tags.join(' ') : '' const categoryContent = post.category ? post.category.join(' ') : '' - let indexContent = [post.title, post.summary, tagContent, categoryContent] + const articleInfo = post.title + post.summary + tagContent + categoryContent + let hit = articleInfo.indexOf(keyword) > -1 + let indexContent = [post.summary] console.log('搜索是否命中缓存', page !== null) if (page !== null) { const contentIds = Object.keys(page.block) @@ -74,16 +76,19 @@ export async function getStaticProps ({ params: { keyword } }) { }) } post.results = [] - let hit = false + let hitCount = 0 const re = new RegExp(`${keyword}`, 'g') - indexContent.forEach(c => { + indexContent.forEach((c, i) => { const index = c.toLowerCase().indexOf(keyword.toLowerCase()) if (index > -1) { hit = true const referText = c?.replace(re, `${keyword}`) post.results.push(`${referText}`) + hitCount += 1 } else { - post.results.push(`${c}`) + if ((post.results.length - 1) / hitCount < 3 || i === 0) { + post.results.push(`${c}`) + } } }) diff --git a/themes/NEXT/components/SearchInput.js b/themes/NEXT/components/SearchInput.js index 153001e0..4ee8165a 100644 --- a/themes/NEXT/components/SearchInput.js +++ b/themes/NEXT/components/SearchInput.js @@ -76,7 +76,7 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => { {(showClean && )}
+ onClick={handleSearch}>