Skip to content

Instantly share code, notes, and snippets.

@gregtap
Created October 14, 2019 16:07
Show Gist options
  • Save gregtap/022b33253968e01914d06a4af5a85f58 to your computer and use it in GitHub Desktop.
Save gregtap/022b33253968e01914d06a4af5a85f58 to your computer and use it in GitHub Desktop.
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