mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-26 05:13:24 +03:00
Extract index view to module.
This commit is contained in:
parent
d77d41984e
commit
628a258f57
43
_layout/Index.elm
Normal file
43
_layout/Index.elm
Normal file
@ -0,0 +1,43 @@
|
||||
module Index exposing (view)
|
||||
|
||||
import Element exposing (Element)
|
||||
import MarkParser
|
||||
|
||||
|
||||
view :
|
||||
List
|
||||
( List String
|
||||
, { body : List (Element msg)
|
||||
, metadata : MarkParser.Metadata msg
|
||||
}
|
||||
)
|
||||
-> Element msg
|
||||
view posts =
|
||||
Element.column [ Element.spacing 20 ]
|
||||
(posts
|
||||
|> List.map postSummary
|
||||
)
|
||||
|
||||
|
||||
postSummary :
|
||||
( List String
|
||||
, { body : List (Element msg)
|
||||
, metadata : MarkParser.Metadata msg
|
||||
}
|
||||
)
|
||||
-> Element msg
|
||||
postSummary ( postPath, post ) =
|
||||
Element.paragraph [] post.metadata.title
|
||||
|> linkToPost postPath
|
||||
|
||||
|
||||
linkToPost : List String -> Element msg -> Element msg
|
||||
linkToPost postPath content =
|
||||
Element.link []
|
||||
{ url = postUrl postPath, label = content }
|
||||
|
||||
|
||||
postUrl : List String -> String
|
||||
postUrl postPath =
|
||||
"/"
|
||||
++ String.join "/" postPath
|
3
elm.json
3
elm.json
@ -2,6 +2,7 @@
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src",
|
||||
"_layout",
|
||||
"gen"
|
||||
],
|
||||
"elm-version": "0.19.0",
|
||||
@ -31,4 +32,4 @@
|
||||
"elm/random": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
module Content exposing (allData, pages, posts)
|
||||
|
||||
import Element exposing (Element)
|
||||
import Index
|
||||
import Mark
|
||||
import Mark.Error
|
||||
import MarkParser
|
||||
@ -32,7 +33,16 @@ allData =
|
||||
let
|
||||
pageListings =
|
||||
pages
|
||||
|> List.map (\( path, markup ) -> ( path, Mark.compile (MarkParser.document Element.none) markup ))
|
||||
|> List.map
|
||||
(\( path, markup ) ->
|
||||
( path
|
||||
, Mark.compile
|
||||
(MarkParser.document
|
||||
(Index.view postListings)
|
||||
)
|
||||
markup
|
||||
)
|
||||
)
|
||||
|> change2
|
||||
in
|
||||
case pageListings of
|
||||
|
Loading…
Reference in New Issue
Block a user