@@ -39,20 +39,6 @@ export const KBarSearchProvider: FC<{
39
39
const [ modalLoaded , setModalLoaded ] = useState ( false )
40
40
const [ dataLoaded , setDataLoaded ] = useState ( false )
41
41
42
- const startingActions = useMemo ( ( ) => {
43
- return Array . isArray ( defaultActions )
44
- ? defaultActions
45
- : [
46
- {
47
- id : 'homepage' ,
48
- name : 'Homepage' ,
49
- keywords : '' ,
50
- section : 'Home' ,
51
- perform : ( ) => router . push ( '/' ) ,
52
- } ,
53
- ]
54
- } , [ defaultActions , router ] )
55
-
56
42
const importDocSearchModalIfNeeded = useCallback ( ( ) => {
57
43
if ( KBarModal ) {
58
44
return Promise . resolve ( )
@@ -73,7 +59,18 @@ export const KBarSearchProvider: FC<{
73
59
}
74
60
}
75
61
const mapPosts = ( posts : CoreContent < MDXDocument > [ ] ) => {
76
- const actions : Action [ ] = [ ]
62
+ const startingActions = Array . isArray ( defaultActions )
63
+ ? defaultActions
64
+ : [
65
+ {
66
+ id : 'homepage' ,
67
+ name : 'Homepage' ,
68
+ keywords : '' ,
69
+ section : 'Home' ,
70
+ perform : ( ) => router . push ( '/' ) ,
71
+ } ,
72
+ ]
73
+ const actions : Action [ ] = startingActions
77
74
for ( const post of posts ) {
78
75
actions . push ( {
79
76
id : post . path ,
@@ -87,7 +84,11 @@ export const KBarSearchProvider: FC<{
87
84
return actions
88
85
}
89
86
async function fetchData ( ) {
90
- const res = await fetch ( searchDocumentsPath )
87
+ const url =
88
+ searchDocumentsPath . indexOf ( '://' ) > 0 || searchDocumentsPath . indexOf ( '//' ) === 0
89
+ ? searchDocumentsPath
90
+ : new URL ( searchDocumentsPath , window . location . origin )
91
+ const res = await fetch ( url )
91
92
const json = await res . json ( )
92
93
const actions = mapPosts ( json )
93
94
setSearchActions ( actions )
@@ -103,14 +104,7 @@ export const KBarSearchProvider: FC<{
103
104
/*removes event listener on cleanup*/
104
105
window . removeEventListener ( 'keydown' , handleKeyDown )
105
106
}
106
- } , [
107
- importDocSearchModalIfNeeded ,
108
- modalLoaded ,
109
- dataLoaded ,
110
- startingActions ,
111
- router ,
112
- searchDocumentsPath ,
113
- ] )
107
+ } , [ importDocSearchModalIfNeeded , modalLoaded , dataLoaded , router , searchDocumentsPath ] )
114
108
115
109
return (
116
110
< >
0 commit comments