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 && (