@@ -59,7 +59,13 @@ let hit = ({hit, children}: DocSearch.hitComponent) => {
59
59
</Next .Link >
60
60
}
61
61
62
+ @val @scope (("window" , "location" )) external pathname : string = "pathname"
62
63
let transformItems = (items : DocSearch .transformItems ) => {
64
+ let version = switch pathname {
65
+ | "/" => Url .Latest
66
+ | other => Url .parse (other ).version
67
+ }
68
+
63
69
items -> Belt .Array .keepMap (item => {
64
70
// Transform absolute URL into relative
65
71
let url = try Util .Url .make (item .url )-> Some catch {
@@ -69,12 +75,25 @@ let transformItems = (items: DocSearch.transformItems) => {
69
75
}
70
76
switch url {
71
77
| Some ({pathname , hash }) =>
72
- let (lvl1 , type_ ) = switch item .hierarchy .lvl1 -> Js .Nullable .toOption {
73
- | Some (_ ) => (item .hierarchy .lvl1 , item .type_ )
74
- | None => (item .hierarchy .lvl0 -> Js .Nullable .return , #lvl1 )
78
+ let versionStr = switch version {
79
+ | Latest | NoVersion => "latest"
80
+ | Version (v ) => v
81
+ }
82
+ let urlVersion = switch Url .parse (pathname ).version {
83
+ | Latest | NoVersion => "latest"
84
+ | Version (v ) => v
85
+ }
86
+
87
+ if urlVersion == versionStr {
88
+ let (lvl1 , type_ ) = switch item .hierarchy .lvl1 -> Js .Nullable .toOption {
89
+ | Some (_ ) => (item .hierarchy .lvl1 , item .type_ )
90
+ | None => (item .hierarchy .lvl0 -> Js .Nullable .return , #lvl1 )
91
+ }
92
+ let hierarchy = {... item .hierarchy , lvl1 }
93
+ {... item , url : pathname ++ hash , hierarchy , type_ }-> Some
94
+ } else {
95
+ None
75
96
}
76
- let hierarchy = {... item .hierarchy , lvl1 }
77
- {... item , url : pathname ++ hash , hierarchy , type_ }-> Some
78
97
| None => None
79
98
}
80
99
})
0 commit comments