mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-26 21:31:32 +03:00
Use Json decoding instead of Yaml decoding for markdown frontmatter.
This commit is contained in:
parent
69a5018ca8
commit
728fef16af
@ -15,7 +15,6 @@ import Pages.Parser exposing (PageOrPost)
|
||||
import Platform.Sub exposing (Sub)
|
||||
import Result.Extra
|
||||
import Url exposing (Url)
|
||||
import Yaml.Decode
|
||||
|
||||
|
||||
type alias Content =
|
||||
@ -110,7 +109,7 @@ combineTupleResults input =
|
||||
|
||||
init :
|
||||
(String -> view)
|
||||
-> Yaml.Decode.Decoder metadata
|
||||
-> Json.Decode.Decoder metadata
|
||||
-> (Json.Encode.Value -> Cmd (Msg userMsg))
|
||||
-> (metadata -> List Head.Tag)
|
||||
-> Parser metadata view
|
||||
@ -136,16 +135,11 @@ init markdownToHtml frontmatterParser toJsPort head parser content initUserModel
|
||||
|> List.map
|
||||
(Tuple.mapSecond
|
||||
(\{ frontMatter, body } ->
|
||||
Yaml.Decode.fromString frontmatterParser frontMatter
|
||||
Json.Decode.decodeString frontmatterParser frontMatter
|
||||
|> Result.map (\parsedFrontmatter -> { parsedFrontmatter = parsedFrontmatter, body = body })
|
||||
|> Result.mapError
|
||||
(\error ->
|
||||
case error of
|
||||
Yaml.Decode.Parsing string ->
|
||||
Html.text string
|
||||
|
||||
Yaml.Decode.Decoding string ->
|
||||
Html.text string
|
||||
Html.text (Json.Decode.errorToString error)
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -268,7 +262,7 @@ application :
|
||||
, content : Content
|
||||
, toJsPort : Json.Encode.Value -> Cmd (Msg userMsg)
|
||||
, head : metadata -> List Head.Tag
|
||||
, frontmatterParser : Yaml.Decode.Decoder metadata
|
||||
, frontmatterParser : Json.Decode.Decoder metadata
|
||||
, markdownToHtml : String -> view
|
||||
}
|
||||
-> Program userFlags userModel userMsg metadata view
|
||||
|
@ -13,7 +13,7 @@ content =
|
||||
markdown : List ( List String, { frontMatter : String, body : String } )
|
||||
markdown =
|
||||
[ ( ["markdown"]
|
||||
, { frontMatter = """title: This is a markdown article
|
||||
, { frontMatter = """{"title":"This is a markdown article"}
|
||||
"""
|
||||
, body = """
|
||||
# Hey there 👋
|
||||
|
@ -6,6 +6,7 @@ import Element exposing (Element)
|
||||
import Element.Border
|
||||
import Element.Font as Font
|
||||
import Html exposing (Html)
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
import List.Extra
|
||||
import Mark
|
||||
@ -21,7 +22,6 @@ import Pages.Parser exposing (PageOrPost)
|
||||
import RawContent
|
||||
import SocialMeta
|
||||
import Url exposing (Url)
|
||||
import Yaml.Decode
|
||||
|
||||
|
||||
port toJsPort : Json.Encode.Value -> Cmd msg
|
||||
@ -60,11 +60,11 @@ markdownToHtml body =
|
||||
|> Element.html
|
||||
|
||||
|
||||
frontmatterParser : Yaml.Decode.Decoder (Metadata.Metadata msg)
|
||||
frontmatterParser : Json.Decode.Decoder (Metadata.Metadata msg)
|
||||
frontmatterParser =
|
||||
Yaml.Decode.field "title" Yaml.Decode.string
|
||||
|> Yaml.Decode.map Metadata.PageMetadata
|
||||
|> Yaml.Decode.map Metadata.Page
|
||||
Json.Decode.field "title" Json.Decode.string
|
||||
|> Json.Decode.map Metadata.PageMetadata
|
||||
|> Json.Decode.map Metadata.Page
|
||||
|
||||
|
||||
type alias Model =
|
||||
|
Loading…
Reference in New Issue
Block a user