Decodes a DatoCMS item with its item ID. Useful to decode items before passing them to the DAST decoder:
type alias ImageItem =
{ url : String
, alt : String
}
itemDecoder : Decoder ImageItem
itemDecoder =
Decode.map2 ImageItem
(Decode.field "url" Json.Decode.string)
(Decode.field "alt" Json.Decode.String)
itemsListDecoder : Decoder (List ( ItemId, ImageItem ))
itemsListDecoder =
StructuredText.Decode.itemDecoder itemDecoder
|> Decode.list
myFieldDecoder : Decoder (StructuredText ImageItem)
myFieldDecoder =
Decode.field "blocks" itemsListDecoder
|> Decode.andThen
(\items ->
Decode.field "value" (StructuredText.Decode.decoder items)
)
Decodes a DatoCMS DAST schema.
It requires a list of items that are used within blocks, inline items and/or item links nodes. If you don't use any of those nodes in your DAST document, you can provide an empty list as below. See
itemDecoderfor a more complex example with items.