Wire in route to staticData.

This commit is contained in:
Dillon Kearns 2021-04-04 20:47:25 -07:00
parent 02c9c16cf3
commit a74254773f
5 changed files with 19 additions and 21 deletions

View File

@ -27,7 +27,7 @@ template : TemplateWithState {} StaticData Model Msg
template =
Template.withStaticData
{ head = head
, staticData = staticData
, staticData = \_ -> staticData
}
|> Template.buildWithLocalState
{ view = view

View File

@ -59,7 +59,7 @@ type alias BlogPost =
template : Template Route DataFromFile
template =
Template.withStaticData
{ staticData = fileRequest
{ staticData = staticData
, head = head
--, route = route
@ -106,9 +106,7 @@ view { static } =
:: (publishedDateView static.frontmatter |> Element.el [ Font.size 16, Font.color (Element.rgba255 0 0 0 0.6) ])
:: Palette.blogHeading static.frontmatter.title
:: articleImageView static.frontmatter.image
:: []
-- TODO render with StaticHttp
--:: Tuple.second rendered
:: static.body
|> List.map (Element.map never)
)
]
@ -187,11 +185,11 @@ type alias DataFromFile =
}
fileRequest : StaticHttp.Request DataFromFile
fileRequest =
staticData : Route -> StaticHttp.Request DataFromFile
staticData route =
StaticFile.request
"content/blog/extensible-markdown-parsing-in-elm.md"
--"content/blog/" ++ route.slug ++ ".md"
--"content/blog/extensible-markdown-parsing-in-elm.md"
("content/blog/" ++ route.slug ++ ".md")
(OptimizedDecoder.map2 DataFromFile
(StaticFile.body
|> OptimizedDecoder.andThen

View File

@ -25,7 +25,7 @@ template : TemplateWithState {} StaticData () Msg
template =
Template.withStaticData
{ head = head
, staticData = staticData
, staticData = \_ -> staticData
}
|> Template.buildNoState { view = view }

View File

@ -53,7 +53,7 @@ import Shared
{-| -}
type alias TemplateWithState routeParams templateStaticData templateModel templateMsg =
{ staticData : StaticHttp.Request templateStaticData
{ staticData : routeParams -> StaticHttp.Request templateStaticData
, view :
templateModel
-> Shared.Model
@ -82,9 +82,9 @@ type alias StaticPayload staticData =
{-| -}
type Builder templateStaticData
type Builder routeParams templateStaticData
= WithStaticData
{ staticData : StaticHttp.Request templateStaticData
{ staticData : routeParams -> StaticHttp.Request templateStaticData
, head :
StaticPayload templateStaticData
-> List (Head.Tag Pages.PathKey)
@ -97,7 +97,7 @@ buildNoState :
StaticPayload templateStaticData
-> Shared.PageView Never
}
-> Builder templateStaticData
-> Builder routeParams templateStaticData
-> TemplateWithState routeParams templateStaticData () Never
buildNoState { view } builderState =
case builderState of
@ -122,7 +122,7 @@ buildWithLocalState :
, update : Shared.Model -> routeParams -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg )
, subscriptions : routeParams -> PagePath Pages.PathKey -> templateModel -> Sub templateMsg
}
-> Builder templateStaticData
-> Builder routeParams templateStaticData
-> TemplateWithState routeParams templateStaticData templateModel templateMsg
buildWithLocalState config builderState =
case builderState of
@ -157,7 +157,7 @@ buildWithSharedState :
, update : routeParams -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Maybe Shared.SharedMsg )
, subscriptions : routeParams -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg
}
-> Builder templateStaticData
-> Builder routeParams templateStaticData
-> TemplateWithState routeParams templateStaticData templateModel templateMsg
buildWithSharedState config builderState =
case builderState of
@ -173,10 +173,10 @@ buildWithSharedState config builderState =
{-| -}
withStaticData :
{ staticData : StaticHttp.Request templateStaticData
{ staticData : routeParams -> StaticHttp.Request templateStaticData
, head : StaticPayload templateStaticData -> List (Head.Tag Pages.PathKey)
}
-> Builder templateStaticData
-> Builder routeParams templateStaticData
withStaticData { staticData, head } =
WithStaticData
{ staticData = staticData
@ -187,9 +187,9 @@ withStaticData { staticData, head } =
{-| -}
noStaticData :
{ head : StaticPayload () -> List (Head.Tag Pages.PathKey) }
-> Builder ()
-> Builder routeParams ()
noStaticData { head } =
WithStaticData
{ staticData = StaticHttp.succeed ()
{ staticData = \_ -> StaticHttp.succeed ()
, head = head
}

View File

@ -154,7 +154,7 @@ view page =
}
}
)
(Template.${moduleName(name)}.template.staticData)
(Template.${moduleName(name)}.template.staticData s)
(Shared.template.staticData)
`
)