From 5bb730d4c2c986d9692d9524d5772b15be12e613 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 1 Mar 2022 17:35:29 +0800 Subject: [PATCH] =?UTF-8?q?replaceAll=E6=96=B9=E6=B3=95=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/search/[keyword].js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 4f7cd942..d1dff9c2 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -60,11 +60,12 @@ export async function getStaticProps ({ params: { keyword } }) { } post.results = [] let hit = false + const re = new RegExp(`${keyword}`, 'g') indexContent.forEach(c => { const index = c.toLowerCase().indexOf(keyword.toLowerCase()) if (index > -1) { hit = true - const referText = c?.replaceAll(keyword, `${keyword}`) + const referText = c?.replace(re, `${keyword}`) post.results.push(`${referText}`) } else { post.results.push(`${c}`)