-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add search components & enhancements (#467)
* feat: add search components & enhancements * chore: extendKeys & keys add more description * chore: migrating fuse extendKeys config fields
- Loading branch information
Showing
11 changed files
with
114 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { computed, onMounted, shallowRef } from 'vue' | ||
import { useSiteConfig } from 'valaxy' | ||
import type { MaybeRefOrGetter } from '@vueuse/shared' | ||
import type { UseFuseOptions } from '@vueuse/integrations/useFuse' | ||
import { useFuse } from '@vueuse/integrations/useFuse' | ||
import type { FuseListItem } from 'valaxy/types' | ||
|
||
export function useFuseSearch<T extends FuseListItem = FuseListItem>( | ||
search: MaybeRefOrGetter<string>, | ||
options?: MaybeRefOrGetter<UseFuseOptions<T>>, | ||
) { | ||
const siteConfig = useSiteConfig() | ||
|
||
const fuseListData = shallowRef<T[]>([]) | ||
|
||
const keys = computed(() => { | ||
const ks = siteConfig.value.fuse.options.keys || [] | ||
return ks.length === 0 ? ['title', 'tags', 'categories', 'excerpt'] : ks | ||
}) | ||
|
||
const defaultOptions: UseFuseOptions<T> = { | ||
fuseOptions: { | ||
includeMatches: true, | ||
findAllMatches: true, | ||
// threshold: 0.99, | ||
// ignoreLocation: true, | ||
|
||
...siteConfig.value.fuse.options, | ||
keys: keys.value, | ||
}, | ||
// resultLimit: resultLimit.value, | ||
// matchAllWhenSearchEmpty: matchAllWhenSearchEmpty.value, | ||
} | ||
const useFuseOptions = computed<UseFuseOptions<T>>(() => ({ | ||
...defaultOptions, | ||
...options, | ||
})) | ||
|
||
const ruse = useFuse<T>(search, fuseListData, useFuseOptions) | ||
|
||
async function fetchFuseListData(path?: string) { | ||
const fuseListDataPath = path | ||
|| (siteConfig.value.fuse.dataPath.startsWith('http') | ||
? siteConfig.value.fuse.dataPath | ||
: `${import.meta.env.BASE_URL}${siteConfig.value.fuse.dataPath}`) | ||
|
||
const res = await fetch(fuseListDataPath) | ||
const data = await res.json() | ||
|
||
if (Array.isArray(data)) | ||
fuseListData.value = data | ||
} | ||
|
||
onMounted(fetchFuseListData) | ||
|
||
return ruse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './fuse' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55ff977
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://672d6b235e81d6a8f8c412c0--valaxy.netlify.app