diff --git a/themes/hexo/LayoutSearch.js b/themes/hexo/LayoutSearch.js index 22abf034..b4dab8a2 100644 --- a/themes/hexo/LayoutSearch.js +++ b/themes/hexo/LayoutSearch.js @@ -1,34 +1,89 @@ - import { useRouter } from 'next/router' -import { useEffect } from 'react' +import { useEffect, useRef } from 'react' import BlogPostListPage from './components/BlogPostListPage' import LayoutBase from './LayoutBase' import SearchInput from './components/SearchInput' -export const LayoutSearch = (props) => { - const { keyword } = props +import { useGlobal } from '@/lib/global' +import TagItemMini from './components/TagItemMini' +import Card from './components/Card' +import Link from 'next/link' + +export const LayoutSearch = props => { + const { keyword, tags, categories } = props + const { locale } = useGlobal() const router = useRouter() const currentSearch = keyword || router?.query?.s let handleTextColor = false + const cRef = useRef(null) useEffect(() => { setTimeout(() => { + // 自动聚焦到搜索框 + cRef.current.focus() if (currentSearch && !handleTextColor) { const container = document.getElementById('container') if (container && container.innerHTML) { const re = new RegExp(`${currentSearch}`, 'gim') - container.innerHTML = container.innerHTML.replace(re, `${currentSearch}`) + container.innerHTML = container.innerHTML.replace( + re, + `${currentSearch}` + ) handleTextColor = true } } - }, - 100) + }, 100) }) - return -
- -
-
- -
-
+ return ( + +
+ + {/* 分类 */} + +
+ + {locale.COMMON.CATEGORY}: +
+
+ {categories.map(category => { + return ( + +
+ + {category.name}({category.count}) +
+ + ) + })} +
+
+ {/* 标签 */} + +
+ + {locale.COMMON.TAGS}: +
+
+ {tags.map(tag => { + return ( +
+ +
+ ) + })} +
+
+
+
+ +
+
+ ) } diff --git a/themes/hexo/LayoutTagIndex.js b/themes/hexo/LayoutTagIndex.js index 662bbe48..89cfcbad 100644 --- a/themes/hexo/LayoutTagIndex.js +++ b/themes/hexo/LayoutTagIndex.js @@ -22,7 +22,7 @@ export const LayoutTagIndex = props => {
{tags.map(tag => { return ( -
+
) diff --git a/themes/hexo/components/SearchInput.js b/themes/hexo/components/SearchInput.js index 438920f7..0f29a3a7 100644 --- a/themes/hexo/components/SearchInput.js +++ b/themes/hexo/components/SearchInput.js @@ -1,12 +1,14 @@ import { useRouter } from 'next/router' import { useImperativeHandle, useRef, useState } from 'react' +import { useGlobal } from '@/lib/global' let lock = false -const SearchInput = (props) => { +const SearchInput = props => { const { currentSearch, cRef, className } = props const [onLoading, setLoadingState] = useState(false) const router = useRouter() const searchInputRef = useRef() + const { locale } = useGlobal() useImperativeHandle(cRef, () => { return { focus: () => { @@ -21,14 +23,15 @@ const SearchInput = (props) => { setLoadingState(true) location.href = '/search/' + key } else { - router.push({ pathname: '/' }).then(r => { - }) + router.push({ pathname: '/' }).then(r => {}) } } - const handleKeyUp = (e) => { - if (e.keyCode === 13) { // 回车 + const handleKeyUp = e => { + if (e.keyCode === 13) { + // 回车 handleSearch(searchInputRef.current.value) - } else if (e.keyCode === 27) { // ESC + } else if (e.keyCode === 27) { + // ESC cleanSearch() } } @@ -37,7 +40,7 @@ const SearchInput = (props) => { } const [showClean, setShowClean] = useState(false) - const updateSearchKey = (val) => { + const updateSearchKey = val => { if (lock) { return } @@ -57,30 +60,44 @@ const SearchInput = (props) => { lock = false } - return
- updateSearchKey(e.target.value)} - defaultValue={currentSearch} - /> + return ( +
+ updateSearchKey(e.target.value)} + defaultValue={currentSearch || ''} + /> -
- -
- - {(showClean && -
- +
+
+ + {showClean && ( +
+ +
)} -
+
+ ) } export default SearchInput diff --git a/themes/next/components/SearchDrawer.js b/themes/next/components/SearchDrawer.js index c7ec88a7..6c1f46b9 100644 --- a/themes/next/components/SearchDrawer.js +++ b/themes/next/components/SearchDrawer.js @@ -28,7 +28,7 @@ const SearchDrawer = ({ cRef, slot }) => {
{/* 背景蒙版 */} -
+
) }