@@ -190,10 +190,23 @@ function DocSearch() {
190
190
const client = algoliasearch ( '1V1Q59JVTR' , '44a7e2e7508ff185f25ac64c0a675f98' ) ;
191
191
const searchIndex = client . initIndex ( 'react-spectrum' ) ;
192
192
const searchOptions = {
193
+ distinct : 1 ,
193
194
highlightPreTag : `<mark class="${ docsStyle . docSearchBoxMark } ">` ,
194
195
highlightPostTag : '</mark>'
195
196
} ;
196
197
198
+ const sectionTitles = {
199
+ 'react-aria' : 'React Aria' ,
200
+ 'react-spectrum' : 'React Spectrum' ,
201
+ 'react-stately' : 'React Stately' ,
202
+ 'internationalized' : 'Internationalized' ,
203
+ 'blog' : 'Blog' ,
204
+ 'architecture' : 'Architecture' ,
205
+ 'contribute' : 'Contribute' ,
206
+ 'releases' : 'Releases' ,
207
+ 'support' : 'Support'
208
+ } ;
209
+
197
210
const [ searchValue , setSearchValue ] = useState ( '' ) ;
198
211
const [ predictions , setPredictions ] = useState ( null ) ;
199
212
const [ suggestions , setSuggestions ] = useState ( null ) ;
@@ -204,10 +217,21 @@ function DocSearch() {
204
217
hits . forEach ( prediction => {
205
218
let hierarchy = prediction . hierarchy ;
206
219
let objectID = prediction . objectID ;
207
- let lvl0 = hierarchy . lvl0 ;
208
- let section = sections . find ( section => section . title === lvl0 ) ;
220
+ let url = prediction . url ;
221
+ let sectionTitle ;
222
+ for ( const [ path , title ] of Object . entries ( sectionTitles ) ) {
223
+ let regexp = new RegExp ( '^.+//.+/' + path + '[/.].+$' , 'i' ) ;
224
+ if ( url . match ( regexp ) ) {
225
+ sectionTitle = title ;
226
+ break ;
227
+ }
228
+ }
229
+ if ( ! sectionTitle ) {
230
+ sectionTitle = 'Documentation' ;
231
+ }
232
+ let section = sections . find ( section => section . title === sectionTitle ) ;
209
233
if ( ! section ) {
210
- section = { title : lvl0 , items : [ ] } ;
234
+ section = { title : sectionTitle , items : [ ] } ;
211
235
sections . push ( section ) ;
212
236
}
213
237
let text = [ ] ;
@@ -230,7 +254,10 @@ function DocSearch() {
230
254
</ Item >
231
255
) ;
232
256
} ) ;
233
- let suggestions = sections . map ( ( section , index ) => < Section key = { `${ index } -lvl0-${ section . title } ` } title = { section . title } > { section . items } </ Section > ) ;
257
+ let titles = Object . values ( sectionTitles ) ;
258
+ sections . forEach ( ( section , index ) => console . log ( index , section . title , titles . indexOf ( section . title ) ) ) ;
259
+ sections = sections . sort ( ( a , b ) => titles . indexOf ( a . title ) < titles . indexOf ( b . title ) ? - 1 : 1 ) ;
260
+ let suggestions = sections . map ( ( section , index ) => < Section key = { `${ index } -${ section . title } ` } title = { section . title } > { section . items } </ Section > ) ;
234
261
setSuggestions ( suggestions ) ;
235
262
} ;
236
263
0 commit comments