Next主题支持algolia全文搜索

This commit is contained in:
tangly1024
2024-01-30 23:14:00 +08:00
parent bb147e4e38
commit 9ab287cb86
3 changed files with 51 additions and 8 deletions

View File

@@ -10,6 +10,7 @@ import SearchDrawer from './SearchDrawer'
import TagGroups from './TagGroups'
import CONFIG from '../config'
import { siteConfig } from '@/lib/config'
import { useNextGlobal } from '..'
let windowTop = 0
@@ -54,6 +55,16 @@ const TopNav = (props) => {
changeShow(!isOpen)
}
const { searchModal } = useNextGlobal()
const showSeachModal = () => {
if (siteConfig('ALGOLIA_APP_ID')) {
searchModal?.current?.openSearch()
} else {
searchDrawer?.current?.show()
}
}
// 搜索栏
const searchDrawerSlot = <>
{categories && (
<section className='mt-8'>
@@ -112,7 +123,7 @@ const TopNav = (props) => {
{/* 右侧功能 */}
<div className='mr-1 flex justify-end items-center text-sm space-x-4 font-serif dark:text-gray-200'>
<div className="cursor-pointer block lg:hidden" onClick={() => { searchDrawer?.current?.show() }}>
<div className="cursor-pointer block lg:hidden" onClick={showSeachModal}>
<i className="mr-2 fas fa-search" />{locale.NAV.SEARCH}
</div>
</div>