@@ -30,30 +30,7 @@ const SearchProvider = ({
30
30
const [ results , setResults ] = useState < SearchResult [ ] > ( [ ] ) ;
31
31
32
32
// Flattens the search index data
33
- const flattenData = ( data : FuseResult < SearchResult > ) => {
34
- const flatData : SearchResult [ ] = [ ] ;
35
- let flatId = 0 ;
36
- Object . entries ( data ) . forEach ( ( [ category , entries ] ) => {
37
- Object . entries ( entries ) . forEach ( ( [ title , docDetails ] ) => {
38
- // Since we are generating these links with Javascript and the
39
- // middleware doesn't prefix the locale automatically, we need to
40
- // do it manually here.
41
- const relativeUrl =
42
- currentLocale === defaultLocale
43
- ? docDetails . relativeUrl
44
- : `/${ currentLocale } ${ docDetails . relativeUrl } ` ;
45
- docDetails . relativeUrl = relativeUrl ;
46
- flatData . push ( {
47
- id : flatId ++ ,
48
- category : category . replace ( "-fallback" , "" ) ,
49
- title,
50
- ...docDetails ,
51
- } ) ;
52
- } ) ;
53
- } ) ;
54
-
55
- return flatData ;
56
- } ;
33
+
57
34
58
35
// Read the search term from query params on first load
59
36
useEffect ( ( ) => {
@@ -80,6 +57,31 @@ const SearchProvider = ({
80
57
}
81
58
82
59
if ( ! searchTerm ) return ;
60
+
61
+ const flattenData = ( data : FuseResult < SearchResult > ) => {
62
+ const flatData : SearchResult [ ] = [ ] ;
63
+ let flatId = 0 ;
64
+ Object . entries ( data ) . forEach ( ( [ category , entries ] ) => {
65
+ Object . entries ( entries ) . forEach ( ( [ title , docDetails ] ) => {
66
+ // Since we are generating these links with Javascript and the
67
+ // middleware doesn't prefix the locale automatically, we need to
68
+ // do it manually here.
69
+ const relativeUrl =
70
+ currentLocale === defaultLocale
71
+ ? docDetails . relativeUrl
72
+ : `/${ currentLocale } ${ docDetails . relativeUrl } ` ;
73
+ docDetails . relativeUrl = relativeUrl ;
74
+ flatData . push ( {
75
+ id : flatId ++ ,
76
+ category : category . replace ( "-fallback" , "" ) ,
77
+ title,
78
+ ...docDetails ,
79
+ } ) ;
80
+ } ) ;
81
+ } ) ;
82
+
83
+ return flatData ;
84
+ } ;
83
85
84
86
let flatData ;
85
87
0 commit comments