mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-13 23:16:47 +00:00
refactor(重构代码增强可读性):
(cherry picked from commit 304107fff915f037326b87cb78629a2cdcd9a5e4)
This commit is contained in:
@@ -98,6 +98,38 @@ export function checkSlugHasMorThanTwoSlash(row) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文章摘要
|
||||
* @param props
|
||||
* @param pageContentText
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function getPageAISummary(props, pageContentText) {
|
||||
const aiSummaryAPI = siteConfig('AI_SUMMARY_API')
|
||||
if (aiSummaryAPI) {
|
||||
const post = props.post
|
||||
const cacheKey = `ai_summary_${post.id}`
|
||||
let aiSummary = await getDataFromCache(cacheKey)
|
||||
if (aiSummary) {
|
||||
props.post.aiSummary = aiSummary
|
||||
} else {
|
||||
const aiSummaryKey = siteConfig('AI_SUMMARY_KEY')
|
||||
const aiSummaryCacheTime = siteConfig('AI_SUMMARY_CACHE_TIME')
|
||||
const wordLimit = siteConfig('AI_SUMMARY_WORD_LIMIT', '1000')
|
||||
let content = ''
|
||||
for (let heading of post.toc) {
|
||||
content += heading.text + ' '
|
||||
}
|
||||
content += pageContentText
|
||||
const combinedText = post.title + ' ' + content
|
||||
const truncatedText = combinedText.slice(0, wordLimit)
|
||||
aiSummary = await getAiSummary(aiSummaryAPI, aiSummaryKey, truncatedText)
|
||||
await setDataToCache(cacheKey, aiSummary, aiSummaryCacheTime)
|
||||
props.post.aiSummary = aiSummary
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理文章数据
|
||||
* @param props
|
||||
@@ -110,8 +142,8 @@ export async function processPostData(props, from) {
|
||||
props.post.blockMap = await getPostBlocks(props.post.id, from)
|
||||
}
|
||||
|
||||
// 目录默认加载
|
||||
if (props.post?.blockMap?.block) {
|
||||
// 目录默认加载
|
||||
props.post.content = Object.keys(props.post.blockMap.block).filter(
|
||||
key => props.post.blockMap.block[key]?.value?.parent_id === props.post.id
|
||||
)
|
||||
@@ -120,33 +152,7 @@ export async function processPostData(props, from) {
|
||||
const { wordCount, readTime } = countWords(pageContentText)
|
||||
props.post.wordCount = wordCount
|
||||
props.post.readTime = readTime
|
||||
const aiSummaryAPI = siteConfig('AI_SUMMARY_API')
|
||||
if (aiSummaryAPI) {
|
||||
const post = props.post
|
||||
const cacheKey = `ai_summary_${post.id}`
|
||||
let aiSummary = await getDataFromCache(cacheKey)
|
||||
if (aiSummary) {
|
||||
props.post.aiSummary = aiSummary
|
||||
} else {
|
||||
const aiSummaryKey = siteConfig('AI_SUMMARY_KEY')
|
||||
const aiSummaryCacheTime = siteConfig('AI_SUMMARY_CACHE_TIME')
|
||||
const wordLimit = siteConfig('AI_SUMMARY_WORD_LIMIT', '1000')
|
||||
let content = ''
|
||||
for (let heading of post.toc) {
|
||||
content += heading.text + ' '
|
||||
}
|
||||
content += pageContentText
|
||||
const combinedText = post.title + ' ' + content
|
||||
const truncatedText = combinedText.slice(0, wordLimit)
|
||||
aiSummary = await getAiSummary(
|
||||
aiSummaryAPI,
|
||||
aiSummaryKey,
|
||||
truncatedText
|
||||
)
|
||||
await setDataToCache(cacheKey, aiSummary, aiSummaryCacheTime)
|
||||
props.post.aiSummary = aiSummary
|
||||
}
|
||||
}
|
||||
await getPageAISummary(props, pageContentText)
|
||||
}
|
||||
|
||||
// 生成全文索引 && JSON.parse(BLOG.ALGOLIA_RECREATE_DATA)
|
||||
|
||||
Reference in New Issue
Block a user