Skip to content

Commit 7ad1342

Browse files
committed
add helper function optionToNull
1 parent ee0d13b commit 7ad1342

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/common/DocFrontmatter.res

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ type t = {
77

88
let decode = json => {
99
open JSON
10+
let optionToNull = opt =>
11+
switch opt {
12+
| Some(String(v)) => Null.Value(v)
13+
| _ => Null
14+
}
1015
switch json {
1116
| Object(dict{
1217
"title": String(title),
@@ -16,18 +21,9 @@ let decode = json => {
1621
}) =>
1722
Some({
1823
title,
19-
metaTitle: switch metaTitle {
20-
| Some(String(v)) => Null.Value(v)
21-
| _ => Null.Null
22-
},
23-
description: switch description {
24-
| Some(String(v)) => Null.Value(v)
25-
| _ => Null.Null
26-
},
27-
canonical: switch canonical {
28-
| Some(String(v)) => Null.Value(v)
29-
| _ => Null.Null
30-
},
24+
metaTitle: metaTitle->optionToNull,
25+
description: description->optionToNull,
26+
canonical: canonical->optionToNull,
3127
})
3228
| _ => None
3329
}

0 commit comments

Comments
 (0)