mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-23 11:55:41 +03:00
Add isPlaceholder helper.
This commit is contained in:
parent
150148de40
commit
d41f4f5c0a
@ -1,4 +1,4 @@
|
||||
module MarkdownCodec exposing (noteTitle, titleAndDescription, withFrontmatter, withoutFrontmatter)
|
||||
module MarkdownCodec exposing (isPlaceholder, noteTitle, titleAndDescription, withFrontmatter, withoutFrontmatter)
|
||||
|
||||
import DataSource exposing (DataSource)
|
||||
import DataSource.File as StaticFile
|
||||
@ -10,6 +10,41 @@ import OptimizedDecoder exposing (Decoder)
|
||||
import Serialize as S
|
||||
|
||||
|
||||
isPlaceholder : String -> DataSource (Maybe ())
|
||||
isPlaceholder filePath =
|
||||
filePath
|
||||
|> StaticFile.bodyWithoutFrontmatter
|
||||
|> DataSource.andThen
|
||||
(\rawContent ->
|
||||
Markdown.Parser.parse rawContent
|
||||
|> Result.mapError (\_ -> "Markdown error")
|
||||
|> Result.map
|
||||
(\blocks ->
|
||||
List.any
|
||||
(\block ->
|
||||
case block of
|
||||
Block.Heading _ inlines ->
|
||||
False
|
||||
|
||||
_ ->
|
||||
True
|
||||
)
|
||||
blocks
|
||||
|> not
|
||||
)
|
||||
|> DataSource.fromResult
|
||||
)
|
||||
|> DataSource.distillSerializeCodec (filePath ++ "-is-placeholder") S.bool
|
||||
|> DataSource.map
|
||||
(\bool ->
|
||||
if bool then
|
||||
Nothing
|
||||
|
||||
else
|
||||
Just ()
|
||||
)
|
||||
|
||||
|
||||
noteTitle : String -> DataSource String
|
||||
noteTitle filePath =
|
||||
titleFromFrontmatter filePath
|
||||
@ -134,8 +169,8 @@ withoutFrontmatter :
|
||||
-> String
|
||||
-> DataSource (List view)
|
||||
withoutFrontmatter renderer filePath =
|
||||
(StaticFile.bodyWithoutFrontmatter
|
||||
filePath
|
||||
(filePath
|
||||
|> StaticFile.bodyWithoutFrontmatter
|
||||
|> DataSource.andThen
|
||||
(\rawBody ->
|
||||
rawBody
|
||||
@ -237,7 +272,8 @@ codec =
|
||||
|
||||
|
||||
tableHeaderCodec :
|
||||
S.Codec Never
|
||||
S.Codec
|
||||
Never
|
||||
(List
|
||||
{ label : List Block.Inline
|
||||
, alignment : Maybe Block.Alignment
|
||||
|
Loading…
Reference in New Issue
Block a user