diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js index ffde6490..cfbbafa8 100644 --- a/lib/notion/getAllPosts.js +++ b/lib/notion/getAllPosts.js @@ -49,7 +49,6 @@ export async function getAllPosts ({ notionPageData, from, pageType }) { }) if (!posts || posts.length === 0) { - console.warn('文章列表为空') const cacheKey = 'page_block_' + BLOG.NOTION_PAGE_ID await delCacheData(cacheKey) } diff --git a/pages/search/[keyword].js b/pages/search/[keyword].js index 90a2bd62..3f6517bc 100644 --- a/pages/search/[keyword].js +++ b/pages/search/[keyword].js @@ -110,18 +110,16 @@ async function filterByMemCache (allPosts, keyword) { // console.log('搜索是否命中缓存', page !== null, indexContent) post.results = [] let hitCount = 0 - const re = new RegExp(`${keyword}`, 'gim') for (const i in indexContent) { const c = indexContent[i] const index = c.toLowerCase().indexOf(keyword.toLowerCase()) - const referText = c?.replace(re, `${keyword}`) if (index > -1) { hit = true hitCount += 1 - post.results.push(`${referText}`) + post.results.push(c) } else { if ((post.results.length - 1) / hitCount < 3 || i === 0) { - post.results.push(`${referText}`) + post.results.push(c) } } } diff --git a/themes/NEXT/LayoutSearch.js b/themes/NEXT/LayoutSearch.js index 34a48e47..0a1c5fcc 100644 --- a/themes/NEXT/LayoutSearch.js +++ b/themes/NEXT/LayoutSearch.js @@ -2,11 +2,21 @@ import LayoutBase from './LayoutBase' import StickyBar from './components/StickyBar' import BlogPostListScroll from './components/BlogPostListScroll' import { useGlobal } from '@/lib/global' +import { useEffect } from 'react' export const LayoutSearch = (props) => { const { locale } = useGlobal() - const { posts } = props - + const { posts, keyword } = props + useEffect(() => { + setTimeout(() => { + const container = document.getElementById('container') + if (container && container.innerHTML) { + const re = new RegExp(`${keyword}`, 'gim') + container.innerHTML = container.innerHTML.replace(re, `${keyword}`) + } + }, + 100) + }) return ( diff --git a/themes/NEXT/components/BlogPostCard.js b/themes/NEXT/components/BlogPostCard.js index 2e104601..2a0d7614 100644 --- a/themes/NEXT/components/BlogPostCard.js +++ b/themes/NEXT/components/BlogPostCard.js @@ -12,8 +12,8 @@ const BlogPostCard = ({ post, showSummary }) => { const { locale } = useGlobal() const showPreview = CONFIG_NEXT.POST_LIST_PREVIEW && post.blockMap return ( - -
+ +
@@ -47,9 +47,8 @@ const BlogPostCard = ({ post, showSummary }) => { {/* 搜索结果 */} {post.results &&

- {post.results.map(r => ...)} -

- } + {post.results.map(r => {r})} +

} {showPreview && post?.blockMap &&