From 5458e88511adc99cf72a8673a96c568f7498d3bd Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Tue, 15 Aug 2023 17:05:47 +0800 Subject: [PATCH] =?UTF-8?q?fix=20nobelium=E4=B8=BB=E9=A2=98=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A1=86=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/nobelium/components/BlogListPage.js | 4 ++-- themes/nobelium/components/SearchInput.js | 7 ++++--- themes/nobelium/index.js | 24 +++++++++++++++++++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/themes/nobelium/components/BlogListPage.js b/themes/nobelium/components/BlogListPage.js index 5be138de..fc6b72ad 100644 --- a/themes/nobelium/components/BlogListPage.js +++ b/themes/nobelium/components/BlogListPage.js @@ -13,11 +13,11 @@ export const BlogListPage = props => { const currentPage = +page const showPrev = currentPage > 1 - const showNext = page < totalPage + const showNext = currentPage < totalPage && posts?.length > 0 const pagePrefix = router.asPath.split('?')[0].replace(/\/page\/[1-9]\d*/, '').replace(/\/$/, '') return ( -
+
{posts?.map(post => ( diff --git a/themes/nobelium/components/SearchInput.js b/themes/nobelium/components/SearchInput.js index a6affd9c..9f1ffdbe 100644 --- a/themes/nobelium/components/SearchInput.js +++ b/themes/nobelium/components/SearchInput.js @@ -4,7 +4,8 @@ import { useImperativeHandle, useRef, useState } from 'react' let lock = false -const SearchInput = ({ currentTag, currentSearch, cRef }) => { +const SearchInput = props => { + const { tag, keyword, cRef } = props const { locale } = useGlobal() const router = useRouter() const searchInputRef = useRef(null) @@ -61,14 +62,14 @@ const SearchInput = ({ currentTag, currentSearch, cRef }) => { updateSearchKey(e.target.value)} - defaultValue={currentSearch || ''} + defaultValue={keyword || ''} />
{ return ( -
+
{/* SEO相关 */} {/* SEO相关 */} @@ -144,7 +144,7 @@ const LayoutPostList = props => { * @returns */ const LayoutSearch = props => { - const { keyword } = props + const { keyword, posts } = props useEffect(() => { if (isBrowser) { replaceSearchResult({ @@ -157,7 +157,25 @@ const LayoutSearch = props => { }) } }, []) - return } /> + + // 在列表中进行实时过滤 + const [filterKey, setFilterKey] = useState('') + let filteredBlogPosts = [] + if (filterKey && posts) { + filteredBlogPosts = posts.filter(post => { + const tagContent = post?.tags ? post?.tags.join(' ') : '' + const searchContent = post.title + post.summary + tagContent + return searchContent.toLowerCase().includes(filterKey.toLowerCase()) + }) + } else { + filteredBlogPosts = deepClone(posts) + } + console.log('posts', props, posts, filteredBlogPosts) + + return }> + + {BLOG.POST_LIST_STYLE === 'page' ? : } + } /**