mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-13 23:16:47 +00:00
feat(原生支持AI摘要功能): 使用一层API作为缓存而非直接请求AI,可以实现缓存/后端保密和预渲染
(cherry picked from commit 611a7d1d5dc7bc200d4390e29217ab8c8f76b0f0)
This commit is contained in:
@@ -6,6 +6,8 @@ import { uploadDataToAlgolia } from '@/lib/plugins/algolia'
|
||||
import { checkSlugHasOneSlash, getRecommendPost } from '@/lib/utils/post'
|
||||
import { idToUuid } from 'notion-utils'
|
||||
import Slug from '..'
|
||||
import { getPageContentText } from '@/pages/search/[keyword]'
|
||||
import { getAiSummary } from '@/lib/plugins/aiSummary'
|
||||
|
||||
/**
|
||||
* 根据notion的slug访问页面
|
||||
@@ -94,6 +96,26 @@ export async function getStaticProps({ params: { prefix, slug }, locale }) {
|
||||
key => props.post.blockMap.block[key]?.value?.parent_id === props.post.id
|
||||
)
|
||||
props.post.toc = getPageTableOfContents(props.post, props.post.blockMap)
|
||||
|
||||
const aiSummaryAPI = siteConfig('AI_SUMMARY_API')
|
||||
if (aiSummaryAPI) {
|
||||
const aiSummaryKey = siteConfig('AI_SUMMARY_KEY')
|
||||
const wordLimit = siteConfig('AI_SUMMARY_WORD_LIMIT', '1000')
|
||||
const post = props.post
|
||||
let content = ''
|
||||
for (let heading of post.toc) {
|
||||
content += heading.text + ' '
|
||||
}
|
||||
content += getPageContentText(post, post.blockMap)
|
||||
const combinedText = post.title + ' ' + content
|
||||
const truncatedText = combinedText.slice(0, wordLimit)
|
||||
|
||||
props.post.aiSummary = await getAiSummary(
|
||||
aiSummaryAPI,
|
||||
aiSummaryKey,
|
||||
truncatedText
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 生成全文索引 && JSON.parse(BLOG.ALGOLIA_RECREATE_DATA)
|
||||
|
||||
Reference in New Issue
Block a user