-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
update-index.mts
43 lines (38 loc) · 1.05 KB
/
update-index.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import algosearch from 'algoliasearch';
import { sync } from 'fumadocs-core/search-algolia/server';
import type { SearchIndex } from 'fumadocs-mdx';
export async function updateSearchIndexes(
indexes: SearchIndex[],
): Promise<void> {
if (!process.env.ALGOLIA_API_KEY) {
console.warn('Algolia API Key not found, skip updating search index.');
return;
}
if (!process.env.NEXT_PUBLIC_ALGOLIA_APP_ID) {
console.warn('Algolia App ID not found, skip updating search index.');
return;
}
const client = algosearch(
process.env.NEXT_PUBLIC_ALGOLIA_APP_ID,
process.env.ALGOLIA_API_KEY,
{
timeouts: {
connect: 60,
read: 180,
write: 180,
},
},
);
await sync(client, {
document: process.env.NEXT_PUBLIC_ALGOLIA_INDEX ?? 'document',
documents: indexes.map((docs) => ({
_id: docs.id,
title: docs.title,
description: docs.description,
url: docs.url,
structured: docs.structuredData,
tag: docs.url.split('/')[2],
})),
});
console.log('search updated');
}