mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-29 14:56:36 +03:00
Add markdown helper function.
This commit is contained in:
parent
ba436fb555
commit
0e5356058a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user