mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-30 23:06:10 +03:00
Refactor type.
This commit is contained in:
parent
d89d7eed05
commit
1b6eb7fd4c
@ -1,6 +1,6 @@
|
||||
module Pages.Document exposing
|
||||
( Document
|
||||
, DocumentParser
|
||||
, DocumentHandler
|
||||
, markupParser
|
||||
, parser
|
||||
)
|
||||
@ -13,18 +13,13 @@ import Mark.Error
|
||||
|
||||
|
||||
type alias Document metadata view =
|
||||
Dict String
|
||||
{ frontmatterParser : String -> Result String metadata
|
||||
, contentParser : String -> Result String view
|
||||
}
|
||||
Dict String (DocumentHandler metadata view)
|
||||
|
||||
|
||||
type alias DocumentParser metadata view =
|
||||
( String
|
||||
, { frontmatterParser : String -> Result String metadata
|
||||
, contentParser : String -> Result String view
|
||||
}
|
||||
)
|
||||
type alias DocumentHandler metadata view =
|
||||
{ frontmatterParser : String -> Result String metadata
|
||||
, contentParser : String -> Result String view
|
||||
}
|
||||
|
||||
|
||||
parser :
|
||||
@ -32,7 +27,7 @@ parser :
|
||||
, metadata : Json.Decode.Decoder metadata
|
||||
, body : String -> Result String view
|
||||
}
|
||||
-> DocumentParser metadata view
|
||||
-> ( String, DocumentHandler metadata view )
|
||||
parser { extension, body, metadata } =
|
||||
( extension
|
||||
, { contentParser = body
|
||||
@ -48,7 +43,7 @@ parser { extension, body, metadata } =
|
||||
markupParser :
|
||||
Mark.Document metadata
|
||||
-> Mark.Document view
|
||||
-> DocumentParser metadata view
|
||||
-> ( String, DocumentHandler metadata view )
|
||||
markupParser metadataParser markBodyParser =
|
||||
( "emu"
|
||||
, { contentParser = renderMarkup markBodyParser
|
||||
|
@ -1,7 +1,7 @@
|
||||
port module PagesNew exposing (PathKey, allPages, allImages, application, images, isValidRoute, pages)
|
||||
port module PagesNew exposing (PathKey, allImages, allPages, application, images, isValidRoute, pages)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Color exposing (Color)
|
||||
import Dict exposing (Dict)
|
||||
import Head
|
||||
import Html exposing (Html)
|
||||
import Json.Decode
|
||||
@ -9,13 +9,13 @@ import Json.Encode
|
||||
import Mark
|
||||
import Pages
|
||||
import Pages.ContentCache exposing (Page)
|
||||
import Pages.Manifest exposing (DisplayMode, Orientation)
|
||||
import Pages.Manifest.Category as Category exposing (Category)
|
||||
import Url.Parser as Url exposing ((</>), s)
|
||||
import Pages.Directory as Directory exposing (Directory)
|
||||
import Pages.Document
|
||||
import Pages.ImagePath as ImagePath exposing (ImagePath)
|
||||
import Pages.Manifest exposing (DisplayMode, Orientation)
|
||||
import Pages.Manifest.Category as Category exposing (Category)
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Pages.Directory as Directory exposing (Directory)
|
||||
import Url.Parser as Url exposing ((</>), s)
|
||||
|
||||
|
||||
type PathKey
|
||||
@ -27,7 +27,6 @@ buildImage path =
|
||||
ImagePath.build PathKey ("images" :: path)
|
||||
|
||||
|
||||
|
||||
buildPage : List String -> PagePath PathKey
|
||||
buildPage path =
|
||||
PagePath.build PathKey path
|
||||
@ -52,7 +51,7 @@ application :
|
||||
, subscriptions : userModel -> Sub userMsg
|
||||
, view : userModel -> List ( PagePath PathKey, metadata ) -> Page metadata view PathKey -> { title : String, body : Html userMsg }
|
||||
, head : metadata -> List (Head.Tag PathKey)
|
||||
, documents : List (Pages.Document.DocumentParser metadata view)
|
||||
, documents : List ( String, Pages.Document.DocumentHandler metadata view )
|
||||
, manifest : Pages.Manifest.Config PathKey
|
||||
, canonicalSiteUrl : String
|
||||
}
|
||||
@ -73,43 +72,45 @@ application config =
|
||||
}
|
||||
|
||||
|
||||
|
||||
allPages : List (PagePath PathKey)
|
||||
allPages =
|
||||
[ (buildPage [ "blog" ])
|
||||
, (buildPage [ "blog", "types-over-conventions" ])
|
||||
, (buildPage [ "docs", "directory-structure" ])
|
||||
, (buildPage [ "docs" ])
|
||||
, (buildPage [ ])
|
||||
[ buildPage [ "blog" ]
|
||||
, buildPage [ "blog", "types-over-conventions" ]
|
||||
, buildPage [ "docs", "directory-structure" ]
|
||||
, buildPage [ "docs" ]
|
||||
, buildPage []
|
||||
]
|
||||
|
||||
|
||||
pages =
|
||||
{ blog =
|
||||
{ index = (buildPage [ "blog" ])
|
||||
, typesOverConventions = (buildPage [ "blog", "types-over-conventions" ])
|
||||
, directory = directoryWithIndex ["blog"]
|
||||
{ index = buildPage [ "blog" ]
|
||||
, typesOverConventions = buildPage [ "blog", "types-over-conventions" ]
|
||||
, directory = directoryWithIndex [ "blog" ]
|
||||
}
|
||||
, docs =
|
||||
{ directoryStructure = (buildPage [ "docs", "directory-structure" ])
|
||||
, index = (buildPage [ "docs" ])
|
||||
, directory = directoryWithIndex ["docs"]
|
||||
{ directoryStructure = buildPage [ "docs", "directory-structure" ]
|
||||
, index = buildPage [ "docs" ]
|
||||
, directory = directoryWithIndex [ "docs" ]
|
||||
}
|
||||
, index = (buildPage [ ])
|
||||
, index = buildPage []
|
||||
, directory = directoryWithIndex []
|
||||
}
|
||||
|
||||
|
||||
images =
|
||||
{ dillon = (buildImage [ "dillon.jpg" ])
|
||||
, icon = (buildImage [ "icon.svg" ])
|
||||
, mountains = (buildImage [ "mountains.jpg" ])
|
||||
{ dillon = buildImage [ "dillon.jpg" ]
|
||||
, icon = buildImage [ "icon.svg" ]
|
||||
, mountains = buildImage [ "mountains.jpg" ]
|
||||
, directory = directoryWithoutIndex []
|
||||
}
|
||||
|
||||
|
||||
allImages : List (ImagePath PathKey)
|
||||
allImages =
|
||||
[(buildImage [ "dillon.jpg" ])
|
||||
, (buildImage [ "icon.svg" ])
|
||||
, (buildImage [ "mountains.jpg" ])
|
||||
[ buildImage [ "dillon.jpg" ]
|
||||
, buildImage [ "icon.svg" ]
|
||||
, buildImage [ "mountains.jpg" ]
|
||||
]
|
||||
|
||||
|
||||
@ -134,37 +135,41 @@ isValidRoute route =
|
||||
|> Err
|
||||
|
||||
|
||||
content : List ( List String, { extension: String, frontMatter : String, body : Maybe String } )
|
||||
content : List ( List String, { extension : String, frontMatter : String, body : Maybe String } )
|
||||
content =
|
||||
[
|
||||
( ["blog"]
|
||||
, { frontMatter = """{"title":"elm-pages blog","type":"blog-index"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( ["blog", "types-over-conventions"]
|
||||
, { frontMatter = """{"type":"blog","author":"Dillon Kearns","title":"Types Over Conventions","description":"TODO","published":"2019-09-09"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( ["docs", "directory-structure"]
|
||||
, { frontMatter = """{"title":"Directory Structure","type":"doc"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( ["docs"]
|
||||
, { frontMatter = """{"title":"Quick Start","type":"doc"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
,
|
||||
( []
|
||||
, { frontMatter = """{"title":"elm-pages - a statically typed site generator","type":"page"}
|
||||
""" , body = Nothing
|
||||
, extension = "md"
|
||||
} )
|
||||
|
||||
[ ( [ "blog" ]
|
||||
, { frontMatter = """{"title":"elm-pages blog","type":"blog-index"}
|
||||
"""
|
||||
, body = Nothing
|
||||
, extension = "md"
|
||||
}
|
||||
)
|
||||
, ( [ "blog", "types-over-conventions" ]
|
||||
, { frontMatter = """{"type":"blog","author":"Dillon Kearns","title":"Types Over Conventions","description":"TODO","published":"2019-09-09"}
|
||||
"""
|
||||
, body = Nothing
|
||||
, extension = "md"
|
||||
}
|
||||
)
|
||||
, ( [ "docs", "directory-structure" ]
|
||||
, { frontMatter = """{"title":"Directory Structure","type":"doc"}
|
||||
"""
|
||||
, body = Nothing
|
||||
, extension = "md"
|
||||
}
|
||||
)
|
||||
, ( [ "docs" ]
|
||||
, { frontMatter = """{"title":"Quick Start","type":"doc"}
|
||||
"""
|
||||
, body = Nothing
|
||||
, extension = "md"
|
||||
}
|
||||
)
|
||||
, ( []
|
||||
, { frontMatter = """{"title":"elm-pages - a statically typed site generator","type":"page"}
|
||||
"""
|
||||
, body = Nothing
|
||||
, extension = "md"
|
||||
}
|
||||
)
|
||||
]
|
||||
|
@ -63,7 +63,7 @@ main =
|
||||
}
|
||||
|
||||
|
||||
markdownDocument : Pages.Document.DocumentParser Metadata ( MarkdownRenderer.TableOfContents, List (Element Msg) )
|
||||
markdownDocument : ( String, Pages.Document.DocumentHandler Metadata ( MarkdownRenderer.TableOfContents, List (Element Msg) ) )
|
||||
markdownDocument =
|
||||
Pages.Document.parser
|
||||
{ extension = "md"
|
||||
|
@ -95,7 +95,7 @@ application :
|
||||
, subscriptions : userModel -> Sub userMsg
|
||||
, view : userModel -> List ( PagePath PathKey, metadata ) -> Page metadata view PathKey -> { title : String, body : Html userMsg }
|
||||
, head : metadata -> List (Head.Tag PathKey)
|
||||
, documents : List (Pages.Document.DocumentParser metadata view)
|
||||
, documents : List ( String, Pages.Document.DocumentHandler metadata view )
|
||||
, manifest : Pages.Manifest.Config PathKey
|
||||
, canonicalSiteUrl : String
|
||||
}
|
||||
@ -173,7 +173,7 @@ application :
|
||||
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
||||
, subscriptions : userModel -> Sub userMsg
|
||||
, view : userModel -> List ( PagePath PathKey, metadata ) -> Page metadata view PathKey -> { title : String, body : Html userMsg }
|
||||
, documents : List (Pages.Document.DocumentParser metadata view)
|
||||
, documents : List ( String, Pages.Document.DocumentHandler metadata view )
|
||||
, head : metadata -> List (Head.Tag PathKey)
|
||||
, manifest : Pages.Manifest.Config PathKey
|
||||
, canonicalSiteUrl : String
|
||||
|
Loading…
Reference in New Issue
Block a user