@@ -30,30 +30,7 @@ const SearchProvider = ({
3030 const [ results , setResults ] = useState < SearchResult [ ] > ( [ ] ) ;
3131
3232 // 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+
5734
5835 // Read the search term from query params on first load
5936 useEffect ( ( ) => {
@@ -80,6 +57,30 @@ const SearchProvider = ({
8057 }
8158
8259 if ( ! searchTerm ) return ;
60+ const flattenData = ( data : FuseResult < SearchResult > ) => {
61+ const flatData : SearchResult [ ] = [ ] ;
62+ let flatId = 0 ;
63+ Object . entries ( data ) . forEach ( ( [ category , entries ] ) => {
64+ Object . entries ( entries ) . forEach ( ( [ title , docDetails ] ) => {
65+ // Since we are generating these links with Javascript and the
66+ // middleware doesn't prefix the locale automatically, we need to
67+ // do it manually here.
68+ const relativeUrl =
69+ currentLocale === defaultLocale
70+ ? docDetails . relativeUrl
71+ : `/${ currentLocale } ${ docDetails . relativeUrl } ` ;
72+ docDetails . relativeUrl = relativeUrl ;
73+ flatData . push ( {
74+ id : flatId ++ ,
75+ category : category . replace ( "-fallback" , "" ) ,
76+ title,
77+ ...docDetails ,
78+ } ) ;
79+ } ) ;
80+ } ) ;
81+
82+ return flatData ;
83+ } ;
8384
8485 let flatData ;
8586
0 commit comments