From df0977240f5d0acb840897a7f62ba3e2617143df Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 2 Mar 2022 12:47:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Comment.js | 8 ++++---- pages/search/[keyword].js | 13 +++++++++---- themes/NEXT/components/SearchInput.js | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) 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 && (
-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}>
From ed69b9a8859ce15ab7e7d149523daf83033b2387 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 2 Mar 2022 13:11:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Tabs=E7=BB=84=E4=BB=B6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Tabs.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/components/Tabs.js b/components/Tabs.js index 67c67e52..56a44478 100644 --- a/components/Tabs.js +++ b/components/Tabs.js @@ -43,9 +43,8 @@ const Tabs = ({ className, children }) => {
{children.map((item, index) => { - return
- {item} + return
+ {currentTab === index && item}
})}