Skip to content

Commit b4aa653

Browse files
committed
feat: add update-search-index action
1 parent 999d1ee commit b4aa653

File tree

8 files changed

+50
-9
lines changed

8 files changed

+50
-9
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Update Search Index
2+
3+
on:
4+
push:
5+
# Run when merging from official repo to check if translations are outdated
6+
branches:
7+
- main
8+
workflow_dispatch: # Allow manual triggering
9+
10+
# Add permissions needed for creating PRs
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
translate:
16+
runs-on: ubuntu-latest
17+
steps:
18+
# Checkout the repository first to access local actions
19+
- name: Checkout code
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 1
23+
- name: Setup Tools
24+
uses: ./.github/actions/setup
25+
- name: Build docs app
26+
shell: bash
27+
run: pnpm build:docs
28+
- name: Run search index update
29+
shell: bash
30+
run: pnpm run update-search-index
31+
env:
32+
ORAMA_PRIVATE_API_KEY_EN: ${{ secrets.ORAMA_PRIVATE_API_KEY_EN }}
33+
ORAMA_PRIVATE_API_KEY_ZH_HANS: ${{ secrets.ORAMA_PRIVATE_API_KEY_ZH_HANS }}
34+

apps/docs/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
EN_DOMAIN=nextjs.im
22
ZH_HANS_DOMAIN=zh-hans.nextjs.im
3-
ORAMA_PRIVATE_API_KEY=
3+
ORAMA_PRIVATE_API_KEY_EN=
4+
ORAMA_PRIVATE_API_KEY_ZH_HANS=

apps/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"build": "next build",
7-
"build:post": "tsx ./scripts/post-build.mts",
7+
"update-search-index": "tsx ./scripts/update-search-index.mts",
88
"dev": "next dev --turbo",
99
"start": "next start",
1010
"postinstall": "fumadocs-mdx",

apps/docs/scripts/update-orama-index.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import { sync } from '../src/lib/orama/orama-cloud';
88
export async function updateSearchIndexes(): Promise<void> {
99
for (const item of ORAMA_CONFIGS) {
1010
const { locale, privateKey, index } = item;
11+
if (!privateKey) {
12+
console.error(`No private key found for locale: ${locale}`);
13+
continue;
14+
}
1115
const manager = new CloudManager({ api_key: privateKey });
12-
1316
// Get all .body files in the static directory
1417
const staticDir = path.join(`.next/server/app/${locale}/static`);
1518
let allRecords: OramaDocument[] = [];

apps/docs/src/lib/orama/config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import type { Locale } from 'next-intl';
2-
// PrivateApiKey is only used in the server
3-
const privateApiKey = process.env.ORAMA_PRIVATE_API_KEY;
42

53
const ORAMA_EN_CONFIG = {
64
locale: 'en',
7-
privateKey: privateApiKey || '',
5+
privateKey: process.env.ORAMA_PRIVATE_API_KEY_EN || '',
86
apiKey: '4DujbZrvGuklBRFcZBtegX3fV1lzNXnU',
97
index: 'vuywlowcbl1w3s2jtvq5ysxl',
108
endpoint: 'https://cloud.orama.run/v1/indexes/en-ai00ky',
@@ -14,7 +12,7 @@ type ORAMA_EN_CONFIG = typeof ORAMA_EN_CONFIG;
1412

1513
const OORAMA_ZH_HANS_CONFIG = {
1614
locale: 'zh-Hans',
17-
privateKey: privateApiKey || '',
15+
privateKey: process.env.ORAMA_PRIVATE_API_KEY_ZH_HANS || '',
1816
apiKey: '6nEUS4tyXiajWxZ8qMEQMzzLoOYTuLSk',
1917
index: 'vcwl00bwd64h3pa8yq8x107y',
2018
endpoint: 'https://cloud.orama.run/v1/indexes/zh-hans-js5ujm',

apps/docs/src/lib/orama/orama-cloud.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export async function sync(
3131
);
3232
await index.insert(chunk);
3333
}
34-
if (autoDeploy) await index.deploy();
34+
if (autoDeploy) {
35+
console.log('Deploying index...');
36+
await index.deploy();
37+
}
3538
console.log('All operations completed');
3639
}
3740

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"lint": "biome lint .",
1010
"lint:fix": "biome lint --write .",
1111
"dev": "pnpm --filter @next-i18n/translate --filter @next-i18n/docs --parallel dev",
12-
"translate": "pnpm --filter @next-i18n/docs translate"
12+
"translate": "pnpm --filter @next-i18n/docs translate",
13+
"build:docs": "pnpm --filter @next-i18n/docs build",
14+
"update-search-index": "pnpm --filter @next-i18n/docs update-search-index"
1315
},
1416
"keywords": [],
1517
"devDependencies": {

0 commit comments

Comments
 (0)