Extract index view to module.

This commit is contained in:
Dillon Kearns 2019-07-22 14:58:26 -07:00
parent d77d41984e
commit 628a258f57
3 changed files with 56 additions and 2 deletions

43
_layout/Index.elm Normal file
View 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

View File

@ -2,6 +2,7 @@
"type": "application",
"source-directories": [
"src",
"_layout",
"gen"
],
"elm-version": "0.19.0",

View File

@ -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