From e0b7fc31ac01544250117f185faa7695db03e171 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Tue, 24 Sep 2024 16:01:11 +0800 Subject: [PATCH] =?UTF-8?q?gitbook=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- styles/globals.css | 4 +++ themes/gitbook/components/SearchInput.js | 34 +++++++++++++++++------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/styles/globals.css b/styles/globals.css index c3a4818e..7c215c46 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -276,3 +276,7 @@ a.avatar-wrapper { img { display: unset; } + +.adsbygoogle { + overflow: hidden; +} diff --git a/themes/gitbook/components/SearchInput.js b/themes/gitbook/components/SearchInput.js index e3120ec6..5c91fd70 100644 --- a/themes/gitbook/components/SearchInput.js +++ b/themes/gitbook/components/SearchInput.js @@ -2,6 +2,7 @@ import { siteConfig } from '@/lib/config' import { deepClone } from '@/lib/utils' import { useGitBookGlobal } from '@/themes/gitbook' import { useImperativeHandle, useRef, useState } from 'react' +import { useHotkeys } from 'react-hotkeys-hook' let lock = false /** @@ -19,6 +20,15 @@ const SearchInput = ({ currentSearch, cRef, className }) => { } }) + /** + * 快捷键设置 + */ + useHotkeys('ctrl+k', e => { + searchInputRef?.current?.focus() + e.preventDefault() + handleSearch() + }) + const handleSearch = () => { // 使用Algolia if (siteConfig('ALGOLIA_APP_ID')) { @@ -29,6 +39,7 @@ const SearchInput = ({ currentSearch, cRef, className }) => { keyword = keyword.trim() } else { setFilteredNavPages(allNavPages) + return } const filterAllNavPages = deepClone(allNavPages) @@ -79,6 +90,7 @@ const SearchInput = ({ currentSearch, cRef, className }) => { const cleanSearch = () => { searchInputRef.current.value = '' handleSearch() + setShowClean(false) } const [showClean, setShowClean] = useState(false) @@ -103,11 +115,20 @@ const SearchInput = ({ currentSearch, cRef, className }) => { } return ( -
+
+
+ +
{ onChange={e => updateSearchKey(e.target.value)} defaultValue={currentSearch} /> -
- + Ctrl+K
{showClean && (