fix: solve one character search bug

This commit is contained in:
CodeMaker-Zhao
2022-12-03 17:44:41 +08:00
parent cabdb1ee9f
commit ffc2636309
6 changed files with 36 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ import { useGlobal } from '@/lib/global'
import { isBrowser } from '@/lib/utils'
import BlogPostListScroll from './components/BlogPostListScroll'
import BlogPostListPage from './components/BlogPostListPage'
import Mark from 'mark.js'
import BLOG from '@/blog.config'
export const LayoutSearch = (props) => {
@@ -12,8 +13,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'
})
}
}, 200)
return (