mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-06 15:10:29 +00:00
清理冗余搜索
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
||||
import { LayoutSearch } from '@/themes'
|
||||
import BLOG from '@/blog.config'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
export async function getStaticProps () {
|
||||
const {
|
||||
@@ -24,7 +27,36 @@ export async function getStaticProps () {
|
||||
}
|
||||
|
||||
const Search = (props) => {
|
||||
return <LayoutSearch {...props} />
|
||||
const { posts } = props
|
||||
let filteredPosts
|
||||
const searchKey = getSearchKey()
|
||||
// 静态过滤
|
||||
if (searchKey) {
|
||||
filteredPosts = posts.filter(post => {
|
||||
const tagContent = post.tags ? post.tags.join(' ') : ''
|
||||
const categoryContent = post.category ? post.category.join(' ') : ''
|
||||
const searchContent = post.title + post.summary + tagContent + categoryContent
|
||||
return searchContent.toLowerCase().includes(searchKey.toLowerCase())
|
||||
})
|
||||
} else {
|
||||
filteredPosts = posts
|
||||
}
|
||||
|
||||
const { locale } = useGlobal()
|
||||
const meta = {
|
||||
title: `${searchKey || ''} | ${locale.NAV.SEARCH} | ${BLOG.TITLE} `,
|
||||
description: BLOG.DESCRIPTION,
|
||||
type: 'website'
|
||||
}
|
||||
return <LayoutSearch {...props} posts={filteredPosts} meta={meta} currentSearch={searchKey} />
|
||||
}
|
||||
|
||||
function getSearchKey () {
|
||||
const router = useRouter()
|
||||
if (router.query && router.query.s) {
|
||||
return router.query.s
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export default Search
|
||||
|
||||
Reference in New Issue
Block a user