Merge pull request #522 from SwwweetOrange/fix/search_one_character_bug

fix: solve one character search bug
This commit is contained in:
tangly1024
2022-12-03 20:39:54 +08:00
committed by GitHub
6 changed files with 36 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ import CategoryGroup from './components/CategoryGroup'
import { useEffect } from 'react'
import { isBrowser } from '@/lib/utils'
import BLOG from '@/blog.config'
import Mark from 'mark.js'
import BlogPostListScroll from './components/BlogPostListScroll'
import BlogPostListPage from './components/BlogPostListPage'
@@ -16,8 +17,12 @@ export const LayoutSearch = (props) => {
setTimeout(() => {
const container = isBrowser() && document.getElementById('container')
if (container && container.innerHTML) {
const re = new RegExp(`${keyword}`, 'gim')
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${keyword}</span>`)
const re = new RegExp(keyword, 'gim')
const instance = new Mark(container)
instance.markRegExp(re, {
element: 'span',
className: 'text-red-500 border-b border-dashed'
})
}
},
100)