@@ -14,20 +14,23 @@ import {
1414} from './types' ;
1515import { createSearchClient , groupBy , noop } from './utils' ;
1616import { createStoredSearches } from './stored-searches' ;
17+ import { Hit } from './Hit' ;
1718import { SearchBox } from './SearchBox' ;
1819import { ScreenState } from './ScreenState' ;
1920import { Footer } from './Footer' ;
2021
2122interface DocSearchProps
22- extends Omit <
23- PublicAutocompleteOptions < InternalDocSearchHit > ,
24- 'onStateChange' | 'getSources'
25- > {
23+ extends Pick < PublicAutocompleteOptions < InternalDocSearchHit > , 'navigator' > {
2624 appId ?: string ;
2725 apiKey : string ;
2826 indexName : string ;
29- searchParameters : any ;
30- onClose ( ) : void ;
27+ searchParameters ?: any ;
28+ onClose ?( ) : void ;
29+ transformItems ?( items : DocSearchHit [ ] ) : DocSearchHit [ ] ;
30+ hitComponent ?( props : {
31+ hit : DocSearchHit ;
32+ children : React . ReactNode ;
33+ } ) : JSX . Element ;
3134}
3235
3336export function DocSearch ( {
@@ -36,7 +39,9 @@ export function DocSearch({
3639 indexName,
3740 searchParameters,
3841 onClose = noop ,
39- ...autocompleteProps
42+ transformItems = x => x ,
43+ hitComponent = Hit ,
44+ navigator,
4045} : DocSearchProps ) {
4146 const [ state , setState ] = React . useState <
4247 AutocompleteState < InternalDocSearchHit >
@@ -107,7 +112,7 @@ export function DocSearch({
107112 initialState : {
108113 query : initialQuery ,
109114 } ,
110- ... autocompleteProps ,
115+ navigator ,
111116 onStateChange ( { state } ) {
112117 setState ( state as any ) ;
113118 } ,
@@ -191,17 +196,7 @@ export function DocSearch({
191196 throw error ;
192197 } )
193198 . then ( ( hits : DocSearchHit [ ] ) => {
194- const formattedHits = hits . map ( hit => {
195- const url = new URL ( hit . url ) ;
196- return {
197- ...hit ,
198- url : hit . url
199- // @TODO : temporary convenience for development.
200- . replace ( url . origin , '' )
201- . replace ( '#__docusaurus' , '' ) ,
202- } ;
203- } ) ;
204- const sources = groupBy ( formattedHits , hit => hit . hierarchy . lvl0 ) ;
199+ const sources = groupBy ( hits , hit => hit . hierarchy . lvl0 ) ;
205200
206201 // We store the `lvl0`s to display them as search suggestions
207202 // in the “no results“ screen.
@@ -224,6 +219,7 @@ export function DocSearch({
224219 return Object . values (
225220 groupBy ( items , item => item . hierarchy . lvl1 )
226221 )
222+ . map ( transformItems )
227223 . map ( hits =>
228224 hits . map ( item => {
229225 return {
@@ -256,6 +252,8 @@ export function DocSearch({
256252 favoriteSearches ,
257253 saveRecentSearch ,
258254 initialQuery ,
255+ navigator ,
256+ transformItems ,
259257 ]
260258 ) ;
261259
@@ -338,6 +336,7 @@ export function DocSearch({
338336 < ScreenState
339337 { ...autocomplete }
340338 state = { state }
339+ hitComponent = { hitComponent }
341340 recentSearches = { recentSearches }
342341 favoriteSearches = { favoriteSearches }
343342 onItemClick = { item => {
0 commit comments