Add markdown helper function.

This commit is contained in:
Dillon Kearns 2021-06-22 22:14:48 -07:00
parent ba436fb555
commit 0e5356058a

View File

@ -42,6 +42,39 @@ withFrontmatter constructor frontmatterDecoder renderer filePath =
)
withoutFrontmatter :
(frontmatter -> List view -> value)
-> Decoder frontmatter
-> Markdown.Renderer.Renderer view
-> String
-> DataSource.DataSource value
withoutFrontmatter constructor frontmatterDecoder renderer filePath =
DataSource.map2 constructor
(StaticFile.onlyFrontmatter
frontmatterDecoder
filePath
)
((StaticFile.bodyWithoutFrontmatter
filePath
|> DataSource.andThen
(\rawBody ->
rawBody
|> Markdown.Parser.parse
|> Result.mapError (\_ -> "Couldn't parse markdown.")
|> DataSource.fromResult
)
)
|> DataSource.distillSerializeCodec ("markdown-blocks-" ++ filePath)
(S.list codec)
|> DataSource.andThen
(\blocks ->
blocks
|> Markdown.Renderer.render renderer
|> DataSource.fromResult
)
)
codec : S.Codec Never Block
codec =
S.customType