mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 23:16:49 +00:00
31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
import LayoutBase from './LayoutBase'
|
|
import BLOG from '@/blog.config'
|
|
import BlogListPage from './components/BlogListPage'
|
|
import BlogListScroll from './components/BlogListScroll'
|
|
import { useRouter } from 'next/router'
|
|
import { useEffect } from 'react'
|
|
import Mark from 'mark.js'
|
|
import { isBrowser } from '@/lib/utils'
|
|
|
|
export const LayoutSearch = (props) => {
|
|
const { keyword } = props
|
|
const router = useRouter()
|
|
const currentSearch = keyword || router?.query?.s
|
|
useEffect(() => {
|
|
setTimeout(() => {
|
|
const container = isBrowser() && document.getElementById('container')
|
|
if (container && container.innerHTML) {
|
|
const re = new RegExp(currentSearch, 'gim')
|
|
const instance = new Mark(container)
|
|
instance.markRegExp(re, {
|
|
element: 'span',
|
|
className: 'text-red-500 border-b border-dashed'
|
|
})
|
|
}
|
|
}, 100)
|
|
})
|
|
return <LayoutBase {...props} currentSearch={currentSearch}>
|
|
{BLOG.POST_LIST_STYLE === 'page' ? <BlogListPage {...props} /> : <BlogListScroll {...props}/>}
|
|
</LayoutBase>
|
|
}
|