Skip to content

Commit f3cb6f3

Browse files
committed
feat: update orama-search
1 parent 6fb5ebc commit f3cb6f3

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

apps/docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
"name": "@next-i18n/docs",
33
"version": "0.0.0",
44
"private": true,
5+
"type": "module",
56
"scripts": {
67
"build": "next build",
7-
"update-search-index": "tsx ./scripts/update-search-index.mts",
8+
"update-search-index": "tsx ./scripts/update-search-index.ts",
89
"dev": "next dev --turbo",
910
"start": "next start",
1011
"postinstall": "fumadocs-mdx",

apps/docs/scripts/update-orama-index.mts renamed to apps/docs/scripts/update-orama-index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as fs from 'node:fs/promises';
22
import * as path from 'node:path';
33
import { ORAMA_CONFIGS_MAP } from '@/lib/orama/config';
4+
import { sync } from '@/lib/orama/orama-cloud';
45
import { CloudManager } from '@oramacloud/client';
56
import type { OramaDocument } from 'fumadocs-core/search/orama-cloud';
67
import type { Locale } from 'next-intl';
7-
import { sync } from '../src/lib/orama/orama-cloud';
88

99
export async function updateSearchIndexes(): Promise<void> {
1010
if (!process.env.ORAMA_PRIVATE_API_KEY) {
@@ -13,7 +13,14 @@ export async function updateSearchIndexes(): Promise<void> {
1313
);
1414
return;
1515
}
16-
const { locale, index } = ORAMA_CONFIGS_MAP[process.env.LOCALE as Locale];
16+
const config = ORAMA_CONFIGS_MAP[process.env.LOCALE as Locale];
17+
if (!config) {
18+
console.warn(
19+
`No Orama config found for locale: ${process.env.LOCALE}. Skipping index update.`,
20+
);
21+
return;
22+
}
23+
const { locale, index } = config;
1724

1825
const manager = new CloudManager({
1926
api_key: process.env.ORAMA_PRIVATE_API_KEY || '',

apps/docs/scripts/update-search-index.mts renamed to apps/docs/scripts/update-search-index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import env from '@next/env';
22
env.loadEnvConfig(process.cwd());
33

4-
console.log(process.env);
5-
6-
import { updateSearchIndexes } from './update-orama-index.mjs';
4+
import { updateSearchIndexes } from './update-orama-index';
75

86
async function main() {
97
console.log('Running post build script...');

apps/docs/src/app/provider.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use client';
22

3+
import { ORAMA_CONFIGS_MAP } from '@/lib/orama/config';
34
import { RootProvider } from 'fumadocs-ui/provider';
5+
import { useLocale } from 'next-intl';
46
import dynamic from 'next/dynamic';
57
import type { ReactNode } from 'react';
68

@@ -9,11 +11,19 @@ const SearchDialog = dynamic(() => import('@/components/search-dialog'), {
911
});
1012

1113
export function Provider({ children }: { children: ReactNode }) {
14+
const locale = useLocale();
15+
const config = ORAMA_CONFIGS_MAP[locale];
1216
return (
1317
<RootProvider
14-
search={{
15-
SearchDialog,
16-
}}
18+
search={
19+
config
20+
? {
21+
SearchDialog,
22+
}
23+
: {
24+
enabled: false,
25+
}
26+
}
1727
>
1828
{children}
1929
</RootProvider>

apps/docs/src/components/search-dialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default function CustomSearchDialog(props: SharedProps) {
1414
const pathname = usePathname();
1515
const locale = useLocale();
1616
const config = ORAMA_CONFIGS_MAP[locale];
17+
if (!config) return null;
1718
const client = useMemo(
1819
() =>
1920
new OramaClient({

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ const OORAMA_ZH_HANT_CONFIG = {
2323
endpoint: 'https://cloud.orama.run/v1/indexes/zh-hant-nvys3a',
2424
};
2525

26-
export const ORAMA_CONFIGS = [ORAMA_EN_CONFIG, OORAMA_ZH_HANS_CONFIG] as const;
27-
2826
export const ORAMA_CONFIGS_MAP: Record<Locale, ORAMA_EN_CONFIG> = {
2927
en: ORAMA_EN_CONFIG,
3028
'zh-hans': OORAMA_ZH_HANS_CONFIG,

apps/docs/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"**/*.ts",
3131
"**/*.tsx",
3232
"**/*.mts",
33-
".next/types/**/*.ts"
33+
".next/types/**/*.ts",
34+
"scripts/**/*.ts"
3435
],
3536
"exclude": ["node_modules"]
3637
}

0 commit comments

Comments
 (0)