Use Template.sandbox for blog post template.

This commit is contained in:
Dillon Kearns 2020-09-13 21:31:49 -07:00
parent a8ab464507
commit 86da9973bd

View File

@ -5,7 +5,6 @@ import Date exposing (Date)
import Element exposing (Element) import Element exposing (Element)
import Element.Font as Font import Element.Font as Font
import Element.Region import Element.Region
import GlobalMetadata
import Head import Head
import Head.Seo as Seo import Head.Seo as Seo
import Json.Decode as Decode import Json.Decode as Decode
@ -17,25 +16,23 @@ import Palette
import Shared import Shared
import Site import Site
import StructuredData import StructuredData
import Template exposing (DynamicPayload, StaticPayload, Template) import Template exposing (DynamicPayload, StaticPayload, Template, TemplateSandbox)
import TemplateMetadata exposing (BlogPost) import TemplateMetadata exposing (BlogPost)
type Model type alias Model =
= Model ()
type Msg type alias Msg =
= Msg Never
template : Template BlogPost () Model Msg template : TemplateSandbox BlogPost
template = template =
Template.simpler Template.sandbox
{ view = view { view = view
, head = head , head = head
, init = init
, update = update
} }
@ -86,24 +83,13 @@ findMatchingImage imageAssetPath =
Pages.allImages Pages.allImages
init : BlogPost -> ( Model, Cmd Msg )
init metadata =
( Model, Cmd.none )
update : BlogPost -> Msg -> DynamicPayload Model -> ( Model, Cmd Msg )
update metadata msg model =
( model.model, Cmd.none )
view : view :
List ( PagePath Pages.PathKey, GlobalMetadata.Metadata ) BlogPost
-> StaticPayload BlogPost () -> PagePath Pages.PathKey
-> Model
-> Shared.RenderedBody -> Shared.RenderedBody
-> Shared.PageView Msg -> Shared.PageView msg
view allMetadata staticPayload model rendered = view metadata path rendered =
{ title = staticPayload.metadata.title { title = metadata.title
, body = , body =
Element.column [ Element.width Element.fill ] Element.column [ Element.width Element.fill ]
[ Element.column [ Element.column
@ -115,19 +101,19 @@ view allMetadata staticPayload model rendered =
] ]
(Element.column [ Element.spacing 10 ] (Element.column [ Element.spacing 10 ]
[ Element.row [ Element.spacing 10 ] [ Element.row [ Element.spacing 10 ]
[ Author.view [] staticPayload.metadata.author [ Author.view [] metadata.author
, Element.column [ Element.spacing 10, Element.width Element.fill ] , Element.column [ Element.spacing 10, Element.width Element.fill ]
[ Element.paragraph [ Font.bold, Font.size 24 ] [ Element.paragraph [ Font.bold, Font.size 24 ]
[ Element.text staticPayload.metadata.author.name [ Element.text metadata.author.name
] ]
, Element.paragraph [ Font.size 16 ] , Element.paragraph [ Font.size 16 ]
[ Element.text staticPayload.metadata.author.bio ] [ Element.text metadata.author.bio ]
] ]
] ]
] ]
:: (publishedDateView staticPayload.metadata |> Element.el [ Font.size 16, Font.color (Element.rgba255 0 0 0 0.6) ]) :: (publishedDateView metadata |> Element.el [ Font.size 16, Font.color (Element.rgba255 0 0 0 0.6) ])
:: Palette.blogHeading staticPayload.metadata.title :: Palette.blogHeading metadata.title
:: articleImageView staticPayload.metadata.image :: articleImageView metadata.image
:: Tuple.second rendered :: Tuple.second rendered
|> List.map (Element.map never) |> List.map (Element.map never)
) )
@ -135,17 +121,20 @@ view allMetadata staticPayload model rendered =
} }
head : StaticPayload BlogPost () -> List (Head.Tag Pages.PathKey) head :
head staticPayload = BlogPost
-> PagePath Pages.PathKey
-> List (Head.Tag Pages.PathKey)
head metadata path =
Head.structuredData Head.structuredData
(StructuredData.article (StructuredData.article
{ title = staticPayload.metadata.title { title = metadata.title
, description = staticPayload.metadata.description , description = metadata.description
, author = StructuredData.person { name = staticPayload.metadata.author.name } , author = StructuredData.person { name = metadata.author.name }
, publisher = StructuredData.person { name = "Dillon Kearns" } , publisher = StructuredData.person { name = "Dillon Kearns" }
, url = Site.canonicalUrl ++ "/" ++ PagePath.toString staticPayload.path , url = Site.canonicalUrl ++ "/" ++ PagePath.toString path
, imageUrl = Site.canonicalUrl ++ "/" ++ ImagePath.toString staticPayload.metadata.image , imageUrl = Site.canonicalUrl ++ "/" ++ ImagePath.toString metadata.image
, datePublished = Date.toIsoString staticPayload.metadata.published , datePublished = Date.toIsoString metadata.published
, mainEntityOfPage = , mainEntityOfPage =
StructuredData.softwareSourceCode StructuredData.softwareSourceCode
{ codeRepositoryUrl = "https://github.com/dillonkearns/elm-pages" { codeRepositoryUrl = "https://github.com/dillonkearns/elm-pages"
@ -159,19 +148,19 @@ head staticPayload =
{ canonicalUrlOverride = Nothing { canonicalUrlOverride = Nothing
, siteName = "elm-pages" , siteName = "elm-pages"
, image = , image =
{ url = staticPayload.metadata.image { url = metadata.image
, alt = staticPayload.metadata.description , alt = metadata.description
, dimensions = Nothing , dimensions = Nothing
, mimeType = Nothing , mimeType = Nothing
} }
, description = staticPayload.metadata.description , description = metadata.description
, locale = Nothing , locale = Nothing
, title = staticPayload.metadata.title , title = metadata.title
} }
|> Seo.article |> Seo.article
{ tags = [] { tags = []
, section = Nothing , section = Nothing
, publishedTime = Just (Date.toIsoString staticPayload.metadata.published) , publishedTime = Just (Date.toIsoString metadata.published)
, modifiedTime = Nothing , modifiedTime = Nothing
, expirationTime = Nothing , expirationTime = Nothing
} }