@@ -59,34 +59,15 @@ let hit = ({hit, children}: DocSearch.hitComponent) => {
5959 </Next .Link >
6060}
6161
62- @val @scope (("window" , "location" )) external pathname : string = "pathname"
6362let transformItems = (items : DocSearch .transformItems ) => {
64- let version = switch pathname {
65- | "/" => Url .Latest
66- | other => Url .parse (other ).version
67- }
6863 items -> Belt .Array .keepMap (item => {
69- // Transform absolute URL into relative
7064 let url = try Webapi .URL .make (item .url )-> Some catch {
7165 | Js .Exn .Error (obj ) =>
7266 Js .Console .error2 (` Failed to parse URL ${item.url}` , obj )
7367 None
7468 }
7569 switch url {
76- | Some ({pathname , hash }) =>
77- let versionStr = switch version {
78- | Latest | NoVersion => "latest"
79- | Version (v ) => v
80- }
81- let urlVersion = switch Url .parse (pathname ).version {
82- | Latest | NoVersion => "latest"
83- | Version (v ) => v
84- }
85- if urlVersion === versionStr {
86- {... item , url : pathname ++ hash }-> Some
87- } else {
88- None
89- }
70+ | Some ({pathname , hash }) => {... item , url : pathname ++ hash }-> Some
9071 | None => None
9172 }
9273 })
@@ -95,6 +76,12 @@ let transformItems = (items: DocSearch.transformItems) => {
9576@react.component
9677let make = () => {
9778 let (state , setState ) = React .useState (_ => Inactive )
79+ let router = Next .Router .useRouter ()
80+
81+ let version = switch Url .parse (router .route ).version {
82+ | Version (v ) => v
83+ | _ => "latest"
84+ }
9885
9986 let handleCloseModal = () => {
10087 let () = switch ReactDOM .querySelector (".DocSearch-Modal" ) {
@@ -162,6 +149,7 @@ let make = () => {
162149 appId
163150 indexName
164151 onClose
152+ searchParameters = {facetFilters : ["version:" ++ version ]}
165153 initialScrollY = {window -> scrollY }
166154 transformItems = {transformItems }
167155 hitComponent = hit
0 commit comments