diff --git a/themes/next/components/SearchInput.js b/themes/next/components/SearchInput.js
index ff763836..1ccf35fc 100644
--- a/themes/next/components/SearchInput.js
+++ b/themes/next/components/SearchInput.js
@@ -1,6 +1,8 @@
import { useRouter } from 'next/router'
import { useGlobal } from '@/lib/global'
import { useImperativeHandle, useRef, useState } from 'react'
+import { useNextGlobal } from '..'
+import { siteConfig } from '@/lib/config'
let lock = false
@@ -9,6 +11,8 @@ const SearchInput = ({ currentTag, keyword, cRef }) => {
const [onLoading, setLoadingState] = useState(false)
const router = useRouter()
const searchInputRef = useRef()
+ const { searchModal } = useNextGlobal()
+
useImperativeHandle(cRef, () => {
return {
focus: () => {
@@ -16,7 +20,21 @@ const SearchInput = ({ currentTag, keyword, cRef }) => {
}
}
})
+
+ const handleFocus = () => {
+ // 使用Algolia
+ if (siteConfig('ALGOLIA_APP_ID')) {
+ searchModal.current.openSearch()
+ }
+ }
+
const handleSearch = () => {
+ // 使用Algolia
+ if (siteConfig('ALGOLIA_APP_ID')) {
+ searchModal.current.openSearch()
+ return
+ }
+
const key = searchInputRef.current.value
if (key && key !== '') {
setLoadingState(true)
@@ -60,18 +78,20 @@ const SearchInput = ({ currentTag, keyword, cRef }) => {
}
}
- return
+ return
{
changeShow(!isOpen)
}
+ const { searchModal } = useNextGlobal()
+ const showSeachModal = () => {
+ if (siteConfig('ALGOLIA_APP_ID')) {
+ searchModal?.current?.openSearch()
+ } else {
+ searchDrawer?.current?.show()
+ }
+ }
+
+ // 搜索栏
const searchDrawerSlot = <>
{categories && (
@@ -112,7 +123,7 @@ const TopNav = (props) => {
{/* 右侧功能 */}
-
{ searchDrawer?.current?.show() }}>
+
{locale.NAV.SEARCH}
diff --git a/themes/next/index.js b/themes/next/index.js
index c2fc59d7..e311c516 100644
--- a/themes/next/index.js
+++ b/themes/next/index.js
@@ -7,7 +7,7 @@ import SideAreaLeft from './components/SideAreaLeft'
import SideAreaRight from './components/SideAreaRight'
import TopNav from './components/TopNav'
import { useGlobal } from '@/lib/global'
-import { useEffect, useRef, useState } from 'react'
+import { createContext, useContext, useEffect, useRef, useState } from 'react'
import BlogPostListScroll from './components/BlogPostListScroll'
import BlogPostListPage from './components/BlogPostListPage'
import StickyBar from './components/StickyBar'
@@ -26,6 +26,11 @@ import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
import CommonHead from '@/components/CommonHead'
import { siteConfig } from '@/lib/config'
+import AlgoliaSearchModal from '@/components/AlgoliaSearchModal'
+
+// 主题全局状态
+const ThemeGlobalNext = createContext()
+export const useNextGlobal = () => useContext(ThemeGlobalNext)
/**
* 基础布局 采用左中右三栏布局,移动端使用顶部导航栏
@@ -74,9 +79,13 @@ const LayoutBase = (props) => {
drawerRight?.current?.handleSwitchVisible()
}} />
+
const tocRef = isBrowser ? document.getElementById('article-wrapper') : null
+ const searchModal = useRef(null)
+
return (
+
{/* SEO相关 */}
@@ -85,6 +94,8 @@ const LayoutBase = (props) => {
{/* 移动端顶部导航栏 */}
+
+
<>{headerSlot}>
{/* 顶部黑线装饰 */}
@@ -135,6 +146,7 @@ const LayoutBase = (props) => {
{/* 页脚 */}
+
)
}