Skip to content

Commit 073cd74

Browse files
committed
fixup!
1 parent 72f6f9c commit 073cd74

3 files changed

Lines changed: 47 additions & 62 deletions

File tree

apps/site/components/withSearch.tsx

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,38 +49,35 @@ export const addPrefixToDocs = <T extends SerializedOramaDb>(
4949
};
5050
};
5151

52+
const loadOrama = async () => {
53+
const db = create({
54+
schema: {
55+
title: 'string',
56+
description: 'string',
57+
href: 'string',
58+
siteSection: 'string',
59+
},
60+
});
61+
62+
const indexes = await Promise.all(
63+
Object.entries(ORAMA_DB_URLS).map(async ([key, url]) => {
64+
const response = await fetch(url);
65+
const fetchedDb = (await response.json()) as SerializedOramaDb;
66+
return addPrefixToDocs(fetchedDb, `/${key}`);
67+
})
68+
);
69+
70+
for (const index of indexes) {
71+
await insertMultiple(db, Object.values(index.docs.docs) as Array<never>);
72+
}
73+
74+
return save(db);
75+
};
76+
5277
const WithSearch: FC = () => {
5378
const t = useTranslations();
5479

55-
// `useOrama` expects an initializer that returns serialized RawData.
56-
// We build a temporary DB, populate it from every configured index, then
57-
// serialize it so the hook can `load()` it into its own client instance.
58-
const client = useOrama(async () => {
59-
const db = create({
60-
schema: {
61-
title: 'string',
62-
description: 'string',
63-
href: 'string',
64-
siteSection: 'string',
65-
},
66-
});
67-
68-
// Kick off every fetch concurrently — network latency, not CPU, is the
69-
// bottleneck here, so serializing these would waste ~N× round-trip time.
70-
const indexes = await Promise.all(
71-
Object.entries(ORAMA_DB_URLS).map(async ([key, url]) => {
72-
const response = await fetch(url);
73-
const fetchedDb = (await response.json()) as SerializedOramaDb;
74-
return addPrefixToDocs(fetchedDb, `/${key}`);
75-
})
76-
);
77-
78-
for (const index of indexes) {
79-
await insertMultiple(db, Object.values(index.docs.docs) as Array<never>);
80-
}
81-
82-
return save(db);
83-
});
80+
const client = useOrama(loadOrama);
8481

8582
return (
8683
<SearchBox

docs/technologies.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This document provides an overview of the technologies used in the Node.js websi
1111
- [PostCSS Plugins](#postcss-plugins)
1212
- [Content Management](#content-management)
1313
- [Content Processing Plugins](#content-processing-plugins)
14+
- [Search](#search)
1415
- [UI Components](#ui-components)
1516
- [Why Radix UI?](#why-radix-ui)
1617
- [Internationalization](#internationalization)
@@ -91,6 +92,12 @@ We chose Next.js because it is:
9192
- `rehype-autolink-headings`: Automatic anchor links for headings
9293
- `rehype-slug`: Automatic ID generation for headings
9394

95+
### Search
96+
97+
- **[Orama](https://orama.com/)**: Local full-text search engine used for site search
98+
- Prebuilt Learn and API documentation indexes are fetched client-side and merged into a single local search database
99+
- Search remains self-contained in the site deployment without depending on Orama Cloud at runtime
100+
94101
### UI Components
95102

96103
- **[Radix UI](https://www.radix-ui.com/)**: Accessible, unstyled component primitives

packages/ui-components/src/Common/Search/index.module.css

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,43 @@
1414
border-t
1515
border-neutral-200
1616
bg-neutral-100
17-
p-4;
18-
19-
:where([data-theme='dark'], [data-theme='dark'] *) & {
20-
@apply border-neutral-900
21-
bg-neutral-950;
22-
}
23-
24-
@media (min-width: 1024px) {
25-
@apply justify-between
26-
rounded-b-xl;
27-
}
17+
p-4
18+
lg:justify-between
19+
lg:rounded-b-xl
20+
dark:border-neutral-900
21+
dark:bg-neutral-950;
2822
}
2923

3024
.shortcutWrapper {
3125
@apply hidden
3226
items-center
33-
gap-2;
34-
35-
@media (min-width: 1024px) {
36-
@apply flex;
37-
}
27+
gap-2
28+
lg:flex;
3829
}
3930

4031
.shortcutItem {
4132
@apply flex
4233
items-center
4334
gap-2
4435
text-xs
45-
text-neutral-800;
46-
47-
:where([data-theme='dark'], [data-theme='dark'] *) & {
48-
@apply text-neutral-600;
49-
}
36+
text-neutral-800
37+
dark:text-neutral-600;
5038
}
5139

5240
.shortcutKey {
5341
@apply rounded-md
5442
bg-neutral-200
5543
p-1
5644
font-mono
57-
text-xs;
58-
59-
:where([data-theme='dark'], [data-theme='dark'] *) & {
60-
@apply bg-neutral-900;
61-
}
45+
text-xs
46+
dark:bg-neutral-900;
6247

6348
svg {
64-
@apply h-4
65-
w-4;
49+
@apply size-4;
6650
}
6751
}
6852

6953
.shortcutLabel {
70-
@apply text-neutral-800;
71-
72-
:where([data-theme='dark'], [data-theme='dark'] *) & {
73-
@apply text-neutral-600;
74-
}
54+
@apply text-neutral-800
55+
dark:text-neutral-600;
7556
}

0 commit comments

Comments
 (0)