Skip to content

Commit

Permalink
fix: expose fuse config (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdrtsky committed Aug 2, 2023
1 parent a92e9e8 commit daf4922
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .starters/default/content/1.introduction/4.configuration.md
Expand Up @@ -132,6 +132,9 @@ export default defineAppConfig({
| `github.repo` | `string` | | Name of the GitHub repo to edit files |
| `github.owner` | `string` | | Owner of the repo |
| `github.edit` | `boolean` | | Toggle "Edit this page on Github" component on documentation pages |
**Search** ||||
| `fuse` | `object` || useFuse [options](https://vueuse.org/integrations/useFuse/) |


## Customizing the logo

Expand Down
4 changes: 3 additions & 1 deletion components/app/AppHeader.vue
Expand Up @@ -24,7 +24,9 @@ defineProps({
</div>
<div class="section right">
<AppSearch />
<AppSearch
:fuse="config.fuse"
/>
<ThemeSelect />
<div class="social-icons">
<AppSocialIcons />
Expand Down
47 changes: 28 additions & 19 deletions components/app/AppSearch.vue
@@ -1,8 +1,29 @@
<script setup lang="ts">
import { useFuse } from '@vueuse/integrations/useFuse'
import { useFuse, UseFuseOptions } from '@vueuse/integrations/useFuse'
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
import { useMagicKeys } from '@vueuse/core'
const props = defineProps({
fuse: {
type: Object as PropType<Partial<UseFuseOptions<DocusSearchResult>>>,
default: () => ({
fuseOptions: {
keys: [
'title',
'description',
'keywords',
'body'
],
ignoreLocation: true,
threshold: 0,
includeMatches: true,
includeScore: true,
},
matchAllWhenSearchEmpty: true
})
},
})
type DocusSearchResult = {
id: string
path: string
Expand Down Expand Up @@ -37,21 +58,7 @@ const { data: files } = await useLazyAsyncData<DocusSearchResult[]>(
const { results } = useFuse<DocusSearchResult>(
q,
files as any,
{
fuseOptions: {
keys: [
'title',
'description',
'keywords',
'body'
],
ignoreLocation: true,
threshold: 0,
includeMatches: true,
includeScore: true,
},
matchAllWhenSearchEmpty: true
}
props.fuse
)
function findNavItem(
Expand Down Expand Up @@ -216,13 +223,15 @@ watch(Escape, () => {
<!-- eslint-disable-next-line vue/no-multiple-template-root -->
<teleport to="body">
<div
ref="searchContentRef"
v-if="show"
ref="searchContentRef"
class="search-content"
@click="show = false"
>
<div @click.stop class="search-window">

<div
class="search-window"
@click.stop
>
<div class="search-input">
<Icon
name="heroicons-outline:search"
Expand Down

0 comments on commit daf4922

Please sign in to comment.