mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-07 23:16:52 +00:00
replaceAll方法替换
This commit is contained in:
@@ -60,11 +60,12 @@ export async function getStaticProps ({ params: { keyword } }) {
|
|||||||
}
|
}
|
||||||
post.results = []
|
post.results = []
|
||||||
let hit = false
|
let hit = false
|
||||||
|
const re = new RegExp(`${keyword}`, 'g')
|
||||||
indexContent.forEach(c => {
|
indexContent.forEach(c => {
|
||||||
const index = c.toLowerCase().indexOf(keyword.toLowerCase())
|
const index = c.toLowerCase().indexOf(keyword.toLowerCase())
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
hit = true
|
hit = true
|
||||||
const referText = c?.replaceAll(keyword, `<span class='text-red-500'>${keyword}</span>`)
|
const referText = c?.replace(re, `<span class='text-red-500'>${keyword}</span>`)
|
||||||
post.results.push(`<span>${referText}</span>`)
|
post.results.push(`<span>${referText}</span>`)
|
||||||
} else {
|
} else {
|
||||||
post.results.push(`<span>${c}</span>`)
|
post.results.push(`<span>${c}</span>`)
|
||||||
|
|||||||
Reference in New Issue
Block a user