mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-02 07:26:45 +00:00
algolia 搜索相关
This commit is contained in:
@@ -9,6 +9,7 @@ import { getPageTableOfContents } from '@/lib/notion/getPageTableOfContents'
|
||||
import { getLayoutByTheme } from '@/themes/theme'
|
||||
import md5 from 'js-md5'
|
||||
import { isBrowser } from '@/lib/utils'
|
||||
import { uploadDataToAlgolia } from '@/lib/algolia'
|
||||
|
||||
/**
|
||||
* 根据notion的slug访问页面
|
||||
@@ -128,6 +129,10 @@ export async function getStaticProps({ params: { slug } }) {
|
||||
props.post.blockMap = await getPostBlocks(props.post.id, from)
|
||||
}
|
||||
|
||||
if (BLOG.ALGOLIA_APP_ID && BLOG.ALGOLIA_APP_KEY) {
|
||||
uploadDataToAlgolia(props?.post)
|
||||
}
|
||||
|
||||
// 推荐关联文章处理
|
||||
const allPosts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
if (allPosts && allPosts.length > 0) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { generateRobotsTxt } from '@/lib/robots.txt'
|
||||
|
||||
import { useRouter } from 'next/router'
|
||||
import { getLayoutByTheme } from '@/themes/theme'
|
||||
|
||||
/**
|
||||
* 首页布局
|
||||
* @param {*} props
|
||||
|
||||
@@ -121,16 +121,7 @@ async function filterByMemCache(allPosts, keyword) {
|
||||
const categoryContent = post.category && Array.isArray(post.category) ? post.category.join(' ') : ''
|
||||
const articleInfo = post.title + post.summary + tagContent + categoryContent
|
||||
let hit = articleInfo.toLowerCase().indexOf(keyword) > -1
|
||||
let indexContent = [post.summary]
|
||||
// 防止搜到加密文章的内容
|
||||
if (page && page.block && !post.password) {
|
||||
const contentIds = Object.keys(page.block)
|
||||
contentIds.forEach(id => {
|
||||
const properties = page?.block[id]?.value?.properties
|
||||
indexContent = appendText(indexContent, properties, 'title')
|
||||
indexContent = appendText(indexContent, properties, 'caption')
|
||||
})
|
||||
}
|
||||
const indexContent = getPageContentText(post, page)
|
||||
// console.log('全文搜索缓存', cacheKey, page != null)
|
||||
post.results = []
|
||||
let hitCount = 0
|
||||
@@ -157,4 +148,18 @@ async function filterByMemCache(allPosts, keyword) {
|
||||
return filterPosts
|
||||
}
|
||||
|
||||
export function getPageContentText(post, pageBlockMap) {
|
||||
let indexContent = []
|
||||
// 防止搜到加密文章的内容
|
||||
if (pageBlockMap && pageBlockMap.block && !post.password) {
|
||||
const contentIds = Object.keys(pageBlockMap.block)
|
||||
contentIds.forEach(id => {
|
||||
const properties = pageBlockMap?.block[id]?.value?.properties
|
||||
indexContent = appendText(indexContent, properties, 'title')
|
||||
indexContent = appendText(indexContent, properties, 'caption')
|
||||
})
|
||||
}
|
||||
return indexContent.join('')
|
||||
}
|
||||
|
||||
export default Index
|
||||
|
||||
Reference in New Issue
Block a user