Created
October 14, 2019 16:07
-
-
Save gregtap/022b33253968e01914d06a4af5a85f58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let parsePrismicHomepageResponse = itemsResult => { | |
switch (itemsResult->Option.getWithDefault(Result.Ok(None))) { | |
| Error(_e) => None | |
| Ok(itemsOption) => | |
switch (itemsOption) { | |
| None => None | |
| Some(items) => | |
let parsed = | |
items->Array.map(item => | |
item##data##body | |
->Array.map(bodyItem => | |
{ | |
"sectionTitle": | |
bodyItem##primary##section_title[0] | |
->Option.getWithDefault({"text": ""})##text, | |
"sectionType": bodyItem##primary##section_type, | |
"sectionItems": | |
bodyItem##items | |
->Array.map(item => | |
switch ( | |
bodyItem##primary##section_type->Section.fromString | |
) { | |
| Recipes => | |
RecipeItem( | |
item##content_id, | |
item##recipe_title->Array.map(t => t##text)[0] | |
->Option.getWithDefault(""), | |
) | |
| Packs => | |
PackItem( | |
item##content_id, | |
item##recipe_title->Array.map(t => t##text)[0] | |
->Option.getWithDefault(""), | |
) | |
| Unknown => UnknownItem | |
} | |
), | |
} | |
) | |
); | |
let prismicData = parsed[0]; | |
prismicData; | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment