Skip to content

Commit

Permalink
fix algolia
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed May 27, 2024
1 parent 19de7e1 commit 2b3311e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/plugins/algolia.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import algoliasearch from 'algoliasearch'
* 生成全文索引
* @param {*} allPages
*/
const generateAlgoliaSearch = async({ allPages, force = false }) => {
const generateAlgoliaSearch = async ({ allPages, force = false }) => {
allPages?.forEach(p => {
// 判断这篇文章是否需要重新创建索引
if (p && !p.password) {
Expand All @@ -19,7 +19,7 @@ const generateAlgoliaSearch = async({ allPages, force = false }) => {
* 上传数据
* 根据上次修改文章日期和上次更新索引数据判断是否需要更新algolia索引
*/
const uploadDataToAlgolia = async(post) => {
const uploadDataToAlgolia = async post => {
// Connect and authenticate with your Algolia app
const client = algoliasearch(BLOG.ALGOLIA_APP_ID, BLOG.ALGOLIA_ADMIN_APP_KEY)

Expand Down Expand Up @@ -61,14 +61,18 @@ const uploadDataToAlgolia = async(post) => {
summary: post.summary,
lastEditedDate: post.lastEditedDate, // 更新文章时间
lastIndexDate: new Date(), // 更新索引时间
content: truncate(getPageContentText(post, post.blockMap), 9000) // 索引9000个字节,因为api限制总请求内容上限1万个字节
content: truncate(getPageContentText(post, post.blockMap), 8192) // 索引8192个字符,API限制总请求内容上限1万个字节
}
// console.log('更新Algolia索引', record)
index.saveObject(record).wait().then(r => {
console.log('Algolia索引更新', r)
}).catch(err => {
console.log('Algolia异常', err)
})
index
.saveObject(record)
.wait()
.then(r => {
console.log('Algolia索引更新', r)
})
.catch(err => {
console.log('Algolia异常', err)
})
}
}

Expand Down

0 comments on commit 2b3311e

Please sign in to comment.