module Static.SubLayout exposing (main) import Element exposing (..) import Element.Font as Font import Html exposing (Html) import Html.Attributes exposing (name) import Json.Decode as D exposing (Decoder) import Markdown import Siteelm.Html as Html import Siteelm.Html.Attributes exposing (charset, content) import Siteelm.Page exposing (Page, page) import Static.View.Header as Header import Static.View.Menu as Menu exposing (Menu) main : Page Preamble main = page { decoder = preambleDecoder , head = viewHead , body = viewBody } {-| Preamble is what you write on the head of the content files. -} type alias Preamble = { title : String , menu : List Menu } {-| Preamble is passed as a JSON string. So it requires a decoder. -} preambleDecoder : Decoder Preamble preambleDecoder = D.map2 Preamble (D.field "title" D.string) (D.field "menu" (D.list Menu.decoder)) {-| Make contents inside the _head_ tag. -} viewHead : Preamble -> String -> List (Html Never) viewHead preamble _ = [ Html.meta [ charset "utf-8" ] , Html.title [] (preamble.title ++ "(sub) | siteelm") , Html.meta [ name "description", content "siteelm with elm-ui" ] ] {-| Make contents inside the _body_ tag. The parameter "body" is usually something like markdown. -} viewBody : Preamble -> String -> List (Html Never) viewBody preamble body = [ layout [ height fill ] <| column [ width (px 720) , centerX , height fill ] [ Header.view , row [ spacing 8, height fill ] [ Menu.view preamble.menu , column [ height fill ] [ link [ Font.color (rgb255 230 140 10) ] { url = "/" , label = text "< home" } , html (Markdown.toHtml [] body) ] ] ] ]