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' ? : } + } /**