mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 23:16:49 +00:00
内存全文索引
This commit is contained in:
@@ -2,7 +2,7 @@ import { getGlobalNotionData } from '@/lib/notion/getNotionData'
|
||||
import { LayoutSearch } from '@/themes'
|
||||
import BLOG from '@/blog.config'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import cache from 'memory-cache'
|
||||
import { getDataFromCache } from '@/lib/cache/cache_manager'
|
||||
|
||||
export async function getStaticPaths () {
|
||||
return {
|
||||
@@ -40,9 +40,9 @@ export async function getStaticProps ({ params: { keyword } }) {
|
||||
} = await getGlobalNotionData({ from: 'search-props', pageType: ['Post'] })
|
||||
|
||||
const filterPosts = []
|
||||
allPosts.forEach(post => {
|
||||
for (const post of allPosts) {
|
||||
const cacheKey = 'page_block_' + post.id
|
||||
const page = cache.get(cacheKey)
|
||||
const page = await getDataFromCache(cacheKey)
|
||||
console.log('读取缓存结果:', cacheKey, page)
|
||||
const tagContent = post.tags ? post.tags.join(' ') : ''
|
||||
const categoryContent = post.category ? post.category.join(' ') : ''
|
||||
@@ -57,14 +57,17 @@ export async function getStaticProps ({ params: { keyword } }) {
|
||||
}
|
||||
post.results = []
|
||||
indexContent.forEach(c => {
|
||||
const index = c.indexOf(keyword)
|
||||
const index = c.toLowerCase().indexOf(keyword.toLowerCase())
|
||||
if (index > -1) {
|
||||
filterPosts.push(post)
|
||||
const referText = c?.replaceAll(keyword, `<span class='text-red-500'>${keyword}</span>`)
|
||||
post.results.push(`<span>${referText}</span>`)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
if (post.results.length > 0) {
|
||||
filterPosts.push(post)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
||||
@@ -41,16 +41,16 @@ const BlogPostCard = ({ post, showSummary }) => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{(!showPreview || showSummary) && <p className='mt-4 mb-24 text-gray-700 dark:text-gray-300 text-sm font-light leading-7'>
|
||||
{post.summary && !post.results}
|
||||
{/* 搜索结果 */}
|
||||
{post.results && <span className='mt-4 text-gray-700 dark:text-gray-300 text-sm font-light leading-7'>
|
||||
{post.results.map(r => <span key={r}><span dangerouslySetInnerHTML={{ __html: r }}/>...</span>)}
|
||||
</span>
|
||||
}
|
||||
|
||||
{(!showPreview || showSummary) && !post.results && <p className='mt-4 mb-24 text-gray-700 dark:text-gray-300 text-sm font-light leading-7'>
|
||||
{post.summary}
|
||||
</p>}
|
||||
|
||||
{/* 搜索结果 */}
|
||||
{post.results && <p className='mt-4 text-gray-700 dark:text-gray-300 text-sm font-light leading-7'>
|
||||
{post.results.map(r => <span key={r}><span dangerouslySetInnerHTML={{ __html: r }}/>...</span>)}
|
||||
</p>
|
||||
}
|
||||
|
||||
{showPreview && post?.blockMap && <div className='overflow-ellipsis truncate'>
|
||||
<NotionRenderer
|
||||
bodyClassName='max-h-full'
|
||||
|
||||
Reference in New Issue
Block a user