mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-15 15:09:25 +00:00
35 lines
715 B
JavaScript
35 lines
715 B
JavaScript
import { useRouter } from 'next/router'
|
|
|
|
export const LayoutSearch = ({
|
|
posts,
|
|
tags,
|
|
categories,
|
|
postCount
|
|
}) => {
|
|
let filteredPosts
|
|
const searchKey = getSearchKey()
|
|
if (searchKey) {
|
|
filteredPosts = posts.filter(post => {
|
|
const tagContent = post.tags ? post.tags.join(' ') : ''
|
|
const searchContent = post.title + post.summary + tagContent
|
|
return searchContent.toLowerCase().includes(searchKey.toLowerCase())
|
|
})
|
|
} else {
|
|
filteredPosts = posts
|
|
}
|
|
|
|
console.log(filteredPosts)
|
|
|
|
return <div>
|
|
Search {searchKey}
|
|
</div>
|
|
}
|
|
|
|
function getSearchKey () {
|
|
const router = useRouter()
|
|
if (router.query && router.query.s) {
|
|
return router.query.s
|
|
}
|
|
return null
|
|
}
|