1
1
import type { DocSearchProps } from '@docsearch/react'
2
- import type { InternalDocSearchHit } from '@docsearch/react/dist/esm/types/index.js'
3
2
import { useSiteData } from '@vuepress/client'
4
3
import { resolveRoutePathFromUrl } from '@vuepress/shared'
5
4
import { debounce } from 'ts-debounce'
6
5
import { useRouter } from 'vue-router'
7
6
8
- interface TransformedDocSearchHit extends InternalDocSearchHit {
9
- routePath : string
10
- }
11
-
12
7
const isSpecialClick = ( event : MouseEvent ) : boolean =>
13
8
event . button === 1 ||
14
9
event . altKey ||
@@ -24,15 +19,6 @@ export const useDocsearchShim = (): Partial<DocSearchProps> => {
24
19
const site = useSiteData ( )
25
20
26
21
return {
27
- // transform full url to route path
28
- transformItems : ( items ) =>
29
- items . map ( ( item ) => ( {
30
- ...item ,
31
- // the `item.url` is full url with protocol and hostname
32
- // so we have to transform it to vue-router path
33
- routePath : resolveRoutePathFromUrl ( item . url , site . value . base ) ,
34
- } ) ) ,
35
-
36
22
// render the hit component with custom `onClick` handler
37
23
hitComponent : ( { hit, children } ) =>
38
24
( {
@@ -48,7 +34,7 @@ export const useDocsearchShim = (): Partial<DocSearchProps> => {
48
34
return
49
35
}
50
36
event . preventDefault ( )
51
- router . push ( ( hit as TransformedDocSearchHit ) . routePath )
37
+ router . push ( resolveRoutePathFromUrl ( hit . url , site . value . base ) )
52
38
} ,
53
39
children,
54
40
} ,
@@ -58,8 +44,8 @@ export const useDocsearchShim = (): Partial<DocSearchProps> => {
58
44
// navigation behavior triggered by `onKeyDown` internally
59
45
navigator : {
60
46
// when pressing Enter without metaKey
61
- navigate : ( { item } ) => {
62
- router . push ( ( item as TransformedDocSearchHit ) . routePath )
47
+ navigate : ( { itemUrl } ) => {
48
+ router . push ( resolveRoutePathFromUrl ( itemUrl , site . value . base ) )
63
49
} ,
64
50
} ,
65
51
0 commit comments