Skip to content

Commit 43d8dc3

Browse files
author
Rajat
committed
Orama integration
1 parent 4d0f3f3 commit 43d8dc3

File tree

9 files changed

+182
-21
lines changed

9 files changed

+182
-21
lines changed

.github/workflows/deploy-docs-new-to-pages.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ jobs:
4949
- name: Build docs site
5050
env:
5151
NEXT_PUBLIC_BASE_PATH: ${{ steps.pages.outputs.base_path }}
52+
NEXT_PUBLIC_ORAMA_DATASOURCE_ID: "bd757e41-d4a8-43c2-9b7d-40d88bdcfb7a"
53+
NEXT_PUBLIC_ORAMA_PROJECT_ID: "f3d9449b-526d-4f63-a44c-b1e3f0916086"
54+
NEXT_PUBLIC_ORAMA_API_KEY: "c1_lixizm9uo-hnVzvlPbb9QJOyUoqHQDuQWIUCpLbhCCejzSV4Ztf-WAbP2Vq"
55+
ORAMA_PRIVATE_API_KEY: ${{ secrets.ORAMA_PRIVATE_API_KEY }}
5256
run: pnpm --filter @courselit/docs-new build
5357

5458
- name: Upload artifact

apps/docs-new/app/layout.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "./global.css";
2-
import { RootProvider } from "fumadocs-ui/provider/next";
32
import type { Metadata } from "next";
43
import type { ReactNode } from "react";
4+
import { DocsProvider } from "@/components/docs-provider";
55

66
export const metadata: Metadata = {
77
title: {
@@ -15,13 +15,7 @@ export default function Layout({ children }: { children: ReactNode }) {
1515
return (
1616
<html lang="en" suppressHydrationWarning>
1717
<body className="min-h-screen">
18-
<RootProvider
19-
search={{
20-
enabled: false,
21-
}}
22-
>
23-
{children}
24-
</RootProvider>
18+
<DocsProvider>{children}</DocsProvider>
2519
</body>
2620
</html>
2721
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { exportSearchIndexes } from "@/lib/export-search-indexes";
2+
3+
export const revalidate = false;
4+
5+
export async function GET() {
6+
return Response.json(await exportSearchIndexes());
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use client";
2+
3+
import { RootProvider } from "fumadocs-ui/provider/next";
4+
import type { ReactNode } from "react";
5+
import SearchDialog from "@/components/search-dialog";
6+
7+
const searchEnabled = Boolean(
8+
process.env.NEXT_PUBLIC_ORAMA_PROJECT_ID &&
9+
process.env.NEXT_PUBLIC_ORAMA_API_KEY,
10+
);
11+
12+
export function DocsProvider({ children }: { children: ReactNode }) {
13+
return (
14+
<RootProvider
15+
search={{
16+
enabled: searchEnabled,
17+
...(searchEnabled ? { SearchDialog } : {}),
18+
}}
19+
>
20+
{children}
21+
</RootProvider>
22+
);
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use client";
2+
3+
import { OramaCloud } from "@orama/core";
4+
import OramaSearchDialog from "fumadocs-ui/components/dialog/search-orama";
5+
6+
const projectId = process.env.NEXT_PUBLIC_ORAMA_PROJECT_ID;
7+
const apiKey = process.env.NEXT_PUBLIC_ORAMA_API_KEY;
8+
9+
const client =
10+
projectId && apiKey
11+
? new OramaCloud({
12+
projectId,
13+
apiKey,
14+
})
15+
: null;
16+
17+
export default function SearchDialog(
18+
props: React.ComponentProps<typeof OramaSearchDialog>,
19+
) {
20+
if (!client) {
21+
return <></>;
22+
}
23+
24+
return <OramaSearchDialog {...props} client={client} showOrama />;
25+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type { OramaDocument } from "fumadocs-core/search/orama-cloud";
2+
import { source } from "@/lib/source";
3+
4+
const includedUrls = new Set([
5+
"/",
6+
"/blog/introduction",
7+
"/communities/introduction",
8+
"/courses/introduction",
9+
"/developers/introduction",
10+
"/downloads/introduction",
11+
"/email-marketing/introduction",
12+
"/getting-started/features",
13+
"/getting-started/quick-start",
14+
"/schools/add-custom-domain",
15+
"/schools/introduction",
16+
"/schools/set-up-payments",
17+
"/schools/sso",
18+
"/self-hosting/introduction",
19+
"/self-hosting/self-host",
20+
"/users/introduction",
21+
"/website/introduction",
22+
"/website/sales-pages",
23+
"/downloads/lead-magnet",
24+
"/email-marketing/broadcasts",
25+
]);
26+
27+
export async function exportSearchIndexes(): Promise<OramaDocument[]> {
28+
return source
29+
.getPages()
30+
.filter((page: any) => includedUrls.has(page.url))
31+
.map((page: any) => ({
32+
id: page.url,
33+
structured: page.data.structuredData,
34+
url: page.url,
35+
title: page.data.title,
36+
description: page.data.description,
37+
}));
38+
}

apps/docs-new/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"build": "next build --webpack",
6+
"build": "next build --webpack && node scripts/sync-content.mjs",
77
"dev": "next dev --turbo",
88
"start": "next start",
99
"postinstall": "fumadocs-mdx"
1010
},
1111
"dependencies": {
12+
"@orama/core": "^1.2.19",
1213
"fumadocs-core": "16.7.1",
1314
"fumadocs-mdx": "14.2.10",
1415
"fumadocs-openapi": "^10.4.1",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { OramaCloud } from "@orama/core";
2+
import { sync } from "fumadocs-core/search/orama-cloud";
3+
import fs from "node:fs/promises";
4+
import path from "node:path";
5+
6+
const requiredEnvVars = [
7+
"NEXT_PUBLIC_ORAMA_PROJECT_ID",
8+
"NEXT_PUBLIC_ORAMA_DATASOURCE_ID",
9+
"ORAMA_PRIVATE_API_KEY",
10+
];
11+
12+
const missingEnvVars = requiredEnvVars.filter((key) => !process.env[key]);
13+
14+
if (missingEnvVars.length > 0) {
15+
throw new Error(
16+
`[orama] Missing required env vars: ${missingEnvVars.join(", ")}`,
17+
);
18+
}
19+
20+
const filePath = path.join(".next", "server", "app", "static.json.body");
21+
22+
async function main() {
23+
const orama = new OramaCloud({
24+
projectId: process.env.NEXT_PUBLIC_ORAMA_PROJECT_ID,
25+
apiKey: process.env.ORAMA_PRIVATE_API_KEY,
26+
});
27+
28+
const content = await fs.readFile(filePath, "utf8");
29+
const records = JSON.parse(content);
30+
31+
await sync(orama, {
32+
index: process.env.NEXT_PUBLIC_ORAMA_DATASOURCE_ID,
33+
documents: records,
34+
});
35+
36+
console.log(`[orama] search updated: ${records.length} records`);
37+
}
38+
39+
void main();

0 commit comments

Comments
 (0)