From 065c8f6a67f5e1456b3b55cd6aa9e3bde9aa9752 Mon Sep 17 00:00:00 2001 From: tangly Date: Sun, 5 Dec 2021 14:10:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E9=A1=B5=EF=BC=9A=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=8F=8A=E9=A1=B5=E9=9D=A2=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/search.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/pages/search.js b/pages/search.js index d1678756..1b1cb3aa 100644 --- a/pages/search.js +++ b/pages/search.js @@ -6,44 +6,46 @@ import BlogPostListScroll from '@/components/BlogPostListScroll' import { useRouter } from 'next/router' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faSearch } from '@fortawesome/free-solid-svg-icons' +import { getNotionPageData } from '@/lib/notion/getNotionData' +import { useGlobal } from '@/lib/global' export async function getStaticProps () { - let posts = await getAllPosts({ from: 'index' }) - posts = posts.filter( - post => post.status[0] === 'Published' && post.type[0] === 'Post' - ) - const tags = await getAllTags(posts) - const categories = await getAllCategories(posts) + const from = 'search-props' + const notionPageData = await getNotionPageData({ from }) + const allPosts = await getAllPosts({ notionPageData, from }) + const categories = await getAllCategories(allPosts) + const tagOptions = notionPageData.tagOptions + const tags = await getAllTags({ allPosts, tagOptions }) - const meta = { - title: `${BLOG.title} | ${BLOG.description} `, - description: BLOG.description, - type: 'website' - } return { props: { - posts, + allPosts, tags, - meta, categories }, revalidate: 1 } } -const Search = ({ posts, tags, meta, categories }) => { +const Search = ({ allPosts, tags, categories }) => { // 处理查询过滤 支持标签、关键词过滤 let filteredPosts = [] const searchKey = getSearchKey() if (searchKey) { - filteredPosts = posts.filter(post => { + filteredPosts = allPosts.filter(post => { const tagContent = post.tags ? post.tags.join(' ') : '' const searchContent = post.title + post.summary + tagContent return searchContent.toLowerCase().includes(searchKey.toLowerCase()) }) } + const { locale } = useGlobal() + const meta = { + title: `${BLOG.title} | ${locale.NAV.SEARCH} `, + description: BLOG.description, + type: 'website' + } return ( - +
搜索词: {searchKey}