Skip to content

Commit 492a73a

Browse files
Add optional nuxt search backend (#100)
* Allow switching search backend in config * Implement nuxt search backend
1 parent 311fd70 commit 492a73a

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

app/app.config.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
export default defineAppConfig({
2+
search: {
3+
backend: 'nuxt', // 'nuxt' | 'algolia',
4+
},
5+
26
ui: {
37
primary: 'purple', // Tailwind color name,
48

59
content: {
610
callout: {
711
// Fix background color of pre > code blocks
8-
wrapper: '[&_pre>code]:!bg-transparent'
9-
}
10-
}
12+
wrapper: '[&_pre>code]:!bg-transparent',
13+
},
14+
},
1115
},
1216

1317
header: {

app/app.vue

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ provide('navigation', navigation);
99
defineOgImage({
1010
url: '/img/og-image.png',
1111
});
12+
13+
const { data: files } = useLazyFetch<ParsedContent[]>('/api/search.json', { default: () => [], server: false });
1214
</script>
1315

1416
<template>
@@ -22,5 +24,14 @@ defineOgImage({
2224
</UMain>
2325

2426
<DocsFooter />
27+
28+
<ClientOnly>
29+
<LazyUContentSearch
30+
ref="searchRef"
31+
:files="files"
32+
:navigation="navigation"
33+
:fuse="{ resultLimit: 42 }"
34+
/>
35+
</ClientOnly>
2536
</div>
2637
</template>

app/components/DocsHeader.vue

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const oasSpec = inject<OpenAPIObject>('openapi', { openapi: '3.0', info: { title
88
99
const { metaSymbol } = useShortcuts();
1010
11-
const { header } = useAppConfig();
11+
const { header, search } = useAppConfig();
1212
const route = useRoute();
1313
1414
const links = computed(() =>
@@ -45,7 +45,7 @@ const navigationTree = computed(() => {
4545
</template>
4646

4747
<template #right>
48-
<ClientOnly>
48+
<ClientOnly v-if="search.backend === 'algolia'">
4949
<UTooltip
5050
text="Search"
5151
:shortcuts="[metaSymbol, 'K']"
@@ -64,6 +64,15 @@ const navigationTree = computed(() => {
6464
</UTooltip>
6565
</ClientOnly>
6666

67+
<UTooltip
68+
v-if="search.backend === 'nuxt'"
69+
text="Search"
70+
:shortcuts="[metaSymbol, 'K']"
71+
:popper="{ strategy: 'absolute' }"
72+
>
73+
<UContentSearchButton :label="null" />
74+
</UTooltip>
75+
6776
<UColorModeButton class="hidden lg:inline-flex" />
6877

6978
<UDivider

server/api/search.json.get.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { serverQueryContent } from '#content/server';
2+
3+
export default eventHandler(async (event) => {
4+
return serverQueryContent(event).where({ _type: 'markdown', navigation: { $ne: false } }).find();
5+
});

0 commit comments

Comments
 (0)