Skip to content

Commit 2e22535

Browse files
committed
add fallback when content is null
1 parent 07109fc commit 2e22535

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/bindings/DocSearch.res

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ type contentType = [
1111
]
1212

1313
type hierarchy = {
14-
lvl0: string,
15-
lvl1: string,
16-
lvl2: Js.Nullable.t<string>,
17-
lvl3: Js.Nullable.t<string>,
18-
lvl4: Js.Nullable.t<string>,
19-
lvl5: Js.Nullable.t<string>,
20-
lvl6: Js.Nullable.t<string>,
14+
"lvl0": string,
15+
"lvl1": string,
16+
"lvl2": Js.Nullable.t<string>,
17+
"lvl3": Js.Nullable.t<string>,
18+
"lvl4": Js.Nullable.t<string>,
19+
"lvl5": Js.Nullable.t<string>,
20+
"lvl6": Js.Nullable.t<string>,
2121
}
2222

2323
type docSearchHit = {

src/components/Search.res

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ let make = () => {
9191
}
9292
}
9393

94-
{...item, url}
94+
let (content, type_) = switch item.content->Js.Nullable.toOption {
95+
| Some(c) => (c->Js.Nullable.return, item.type_)
96+
| None =>
97+
let fallback = item.hierarchy["lvl0"]
98+
(fallback->Js.Nullable.return, #content)
99+
}
100+
101+
{...item, url, content, type_}
95102
})
96103
}}
97104
/>,

0 commit comments

Comments
 (0)