mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-19 15:09:36 +00:00
algolia 搜索相关
This commit is contained in:
29
lib/algolia.js
Normal file
29
lib/algolia.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import BLOG from '@/blog.config'
|
||||
import { getPageContentText } from '@/pages/search/[keyword]'
|
||||
import algoliasearch from 'algoliasearch'
|
||||
|
||||
/**
|
||||
* 上传数据
|
||||
*/
|
||||
const uploadDataToAlgolia = (post) => {
|
||||
// Connect and authenticate with your Algolia app
|
||||
const client = algoliasearch(BLOG.ALGOLIA_APP_ID, BLOG.ALGOLIA_APP_KEY)
|
||||
|
||||
// Create a new index and add a record
|
||||
const index = client.initIndex(BLOG.ALGOLIA_INDEX)
|
||||
const record = {
|
||||
objectID: post.id,
|
||||
title: post.title,
|
||||
category: post.category,
|
||||
tags: post.tags,
|
||||
pageCover: post.pageCover,
|
||||
slug: post.slug,
|
||||
summary: post.summary,
|
||||
content: getPageContentText(post, post.blockMap)
|
||||
}
|
||||
index.saveObject(record).wait().then(r => {
|
||||
console.log('Algolia索引', r, record)
|
||||
})
|
||||
}
|
||||
|
||||
export { uploadDataToAlgolia }
|
||||
@@ -185,10 +185,10 @@ export function getNavPages({ allPages }) {
|
||||
const result = allNavPages.map(item => ({ id: item.id, title: item.title || '', category: item.category || null, tags: item.tags || null, summary: item.summary || null, slug: item.slug }))
|
||||
|
||||
const groupedArray = result.reduce((groups, item) => {
|
||||
const categoryName = item.category ? item.category.join('/') : '' // 将category转换为字符串
|
||||
const categoryName = item?.category ? item?.category : '' // 将category转换为字符串
|
||||
const lastGroup = groups[groups.length - 1] // 获取最后一个分组
|
||||
|
||||
if (!lastGroup || lastGroup.category !== categoryName) { // 如果当前元素的category与上一个元素不同,则创建新分组
|
||||
if (!lastGroup || lastGroup?.category !== categoryName) { // 如果当前元素的category与上一个元素不同,则创建新分组
|
||||
groups.push({ category: categoryName, items: [] })
|
||||
}
|
||||
|
||||
|
||||
@@ -69,9 +69,10 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
||||
})
|
||||
}
|
||||
|
||||
// type\status是下拉选框 取数组第一个
|
||||
properties.type = properties.type?.[0]
|
||||
properties.status = properties.status?.[0]
|
||||
// type\status\category 是单选下拉框 取数组第一个
|
||||
properties.type = properties.type?.[0] || ''
|
||||
properties.status = properties.status?.[0] || ''
|
||||
properties.category = properties.category?.[0] || ''
|
||||
|
||||
// 映射值:用户个性化type和status字段的下拉框选项,在此映射回代码的英文标识
|
||||
mapProperties(properties)
|
||||
|
||||
Reference in New Issue
Block a user