Wire through route type.

This commit is contained in:
Dillon Kearns 2021-04-01 21:23:55 -07:00
parent dd81c22ec4
commit b244a70e44
13 changed files with 206 additions and 214 deletions

View File

@ -58,32 +58,32 @@ socialIcon =
--main : Pages.Platform.Program Model Msg Metadata View Pages.PathKey
main : Pages.Platform.Program TemplateModulesBeta.Model TemplateModulesBeta.Msg NoMetadata Shared.RenderedBody Pages.PathKey
main : Pages.Platform.Program TemplateModulesBeta.Model TemplateModulesBeta.Msg (Maybe TemplateModulesBeta.Route) Shared.RenderedBody Pages.PathKey
main =
TemplateModulesBeta.mainTemplate
{ documents =
[ { extension = "md"
, metadata = Json.Decode.succeed NoMetadata -- MetadataNew.decoder -- metadata parser/decoder?
, body = MarkdownRenderer.view -- body parser?
}
[--{ extension = "md"
-- , metadata = Json.Decode.succeed NoMetadata -- MetadataNew.decoder -- metadata parser/decoder?
-- , body = MarkdownRenderer.view -- body parser?
-- }
]
, site = Site.config
}
|> RssPlugin.generate
{ siteTagline = Site.tagline
, siteUrl = Site.canonicalUrl
, title = "elm-pages Blog"
, builtAt = Pages.builtAt
, indexPage = Pages.pages.blog.index
}
metadataToRssItem
|> MySitemap.install { siteUrl = Site.canonicalUrl } metadataToSitemapEntry
|> Pages.Platform.withGlobalHeadTags
[ Head.icon [ ( 32, 32 ) ] MimeType.Png (cloudinaryIcon MimeType.Png 32)
, Head.icon [ ( 16, 16 ) ] MimeType.Png (cloudinaryIcon MimeType.Png 16)
, Head.appleTouchIcon (Just 180) (cloudinaryIcon MimeType.Png 180)
, Head.appleTouchIcon (Just 192) (cloudinaryIcon MimeType.Png 192)
]
--|> RssPlugin.generate
-- { siteTagline = Site.tagline
-- , siteUrl = Site.canonicalUrl
-- , title = "elm-pages Blog"
-- , builtAt = Pages.builtAt
-- , indexPage = Pages.pages.blog.index
-- }
-- metadataToRssItem
--|> MySitemap.install { siteUrl = Site.canonicalUrl } metadataToSitemapEntry
--|> Pages.Platform.withGlobalHeadTags
-- [ Head.icon [ ( 32, 32 ) ] MimeType.Png (cloudinaryIcon MimeType.Png 32)
-- , Head.icon [ ( 16, 16 ) ] MimeType.Png (cloudinaryIcon MimeType.Png 16)
-- , Head.appleTouchIcon (Just 180) (cloudinaryIcon MimeType.Png 180)
-- , Head.appleTouchIcon (Just 192) (cloudinaryIcon MimeType.Png 192)
-- ]
|> Pages.Platform.toProgram

View File

@ -22,7 +22,7 @@ import Palette
import Secrets
type alias SharedTemplate templateDemuxMsg msg1 msg2 =
type alias SharedTemplate route templateDemuxMsg msg1 msg2 =
{ init :
Maybe
{ path :
@ -30,7 +30,7 @@ type alias SharedTemplate templateDemuxMsg msg1 msg2 =
, query : Maybe String
, fragment : Maybe String
}
, metadata : NoMetadata
, metadata : route
}
-> ( Model, Cmd Msg )
, update : Msg -> Model -> ( Model, Cmd Msg )
@ -38,7 +38,7 @@ type alias SharedTemplate templateDemuxMsg msg1 msg2 =
StaticData
->
{ path : PagePath Pages.PathKey
, frontmatter : NoMetadata
, frontmatter : route
}
-> Model
-> (Msg -> templateDemuxMsg)
@ -58,7 +58,7 @@ type alias SharedTemplate templateDemuxMsg msg1 msg2 =
}
template : SharedTemplate msg msg1 msg2
template : SharedTemplate route msg msg1 msg2
template =
{ init = init
, update = update
@ -117,7 +117,7 @@ init :
, query : Maybe String
, fragment : Maybe String
}
, metadata : NoMetadata
, metadata : route
}
-> ( Model, Cmd Msg )
init maybePagePath =
@ -161,7 +161,7 @@ view :
StaticData
->
{ path : PagePath Pages.PathKey
, frontmatter : NoMetadata
, frontmatter : route
}
-> Model
-> (Msg -> msg)

View File

@ -7,7 +7,6 @@ import Element exposing (Element)
import Head
import Head.Seo as Seo
import Index
import NoMetadata exposing (NoMetadata)
import OptimizedDecoder
import Pages exposing (images)
import Pages.ImagePath exposing (ImagePath)
@ -24,7 +23,7 @@ type Msg
= Msg
template : TemplateWithState StaticData Model Msg
template : TemplateWithState {} StaticData Model Msg
template =
Template.withStaticData
{ head = head
@ -50,14 +49,14 @@ type alias StaticData =
List ( PagePath Pages.PathKey, Article.ArticleMetadata )
init : NoMetadata -> ( Model, Cmd Msg )
init : {} -> ( Model, Cmd Msg )
init _ =
( Model, Cmd.none )
update :
Shared.Model
-> NoMetadata
-> {}
-> Msg
-> Model
-> ( Model, Cmd Msg )

View File

@ -56,7 +56,7 @@ type alias BlogPost =
}
template : Template DataFromFile
template : Template {} DataFromFile
template =
Template.withStaticData
{ staticData = fileRequest

View File

@ -36,7 +36,7 @@ type Msg
= Increment
template : TemplateWithState StaticData Model Msg
template : TemplateWithState {} StaticData Model Msg
template =
Template.noStaticData { head = head }
|> Template.buildWithSharedState
@ -47,12 +47,12 @@ template =
}
init : NoMetadata -> ( Model, Cmd Msg )
init : {} -> ( Model, Cmd Msg )
init _ =
( {}, Cmd.none )
update : NoMetadata -> Msg -> Model -> Shared.Model -> ( Model, Cmd Msg, Maybe Shared.SharedMsg )
update : {} -> Msg -> Model -> Shared.Model -> ( Model, Cmd Msg, Maybe Shared.SharedMsg )
update _ msg model sharedModel =
case msg of
Increment ->

View File

@ -20,7 +20,7 @@ type alias Msg =
Never
template : Template ()
template : Template {} ()
template =
Template.noStaticData { head = head }
|> Template.buildNoState { view = view }

View File

@ -25,7 +25,7 @@ type alias Msg =
Never
template : TemplateWithState StaticData () Msg
template : TemplateWithState {} StaticData () Msg
template =
Template.withStaticData
{ head = head

View File

@ -54,7 +54,7 @@ import TemplateType exposing (TemplateType)
{-| -}
type alias TemplateWithState templateStaticData templateModel templateMsg =
type alias TemplateWithState routeParams templateStaticData templateModel templateMsg =
{ staticData : StaticHttp.Request templateStaticData
, view :
templateModel
@ -65,15 +65,15 @@ type alias TemplateWithState templateStaticData templateModel templateMsg =
, head :
StaticPayload templateStaticData
-> List (Head.Tag Pages.PathKey)
, init : NoMetadata -> ( templateModel, Cmd templateMsg )
, update : NoMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Maybe Shared.SharedMsg )
, subscriptions : NoMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg
, init : routeParams -> ( templateModel, Cmd templateMsg )
, update : routeParams -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Maybe Shared.SharedMsg )
, subscriptions : routeParams -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg
}
{-| -}
type alias Template staticData =
TemplateWithState staticData () Never
type alias Template routeParams staticData =
TemplateWithState routeParams staticData () Never
{-| -}
@ -102,7 +102,7 @@ buildNoState :
-> Shared.PageView Never
}
-> Builder NoMetadata templateStaticData
-> TemplateWithState templateStaticData () Never
-> TemplateWithState routeParams templateStaticData () Never
buildNoState { view } builderState =
case builderState of
WithStaticData record ->
@ -123,12 +123,12 @@ buildWithLocalState :
-> StaticPayload templateStaticData
-> Shared.RenderedBody
-> Shared.PageView templateMsg
, init : NoMetadata -> ( templateModel, Cmd templateMsg )
, update : Shared.Model -> NoMetadata -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg )
, subscriptions : NoMetadata -> PagePath Pages.PathKey -> templateModel -> Sub templateMsg
, init : routeParams -> ( templateModel, Cmd templateMsg )
, update : Shared.Model -> routeParams -> templateMsg -> templateModel -> ( templateModel, Cmd templateMsg )
, subscriptions : routeParams -> PagePath Pages.PathKey -> templateModel -> Sub templateMsg
}
-> Builder NoMetadata templateStaticData
-> TemplateWithState templateStaticData templateModel templateMsg
-> Builder routeParams templateStaticData
-> TemplateWithState routeParams templateStaticData templateModel templateMsg
buildWithLocalState config builderState =
case builderState of
WithStaticData record ->
@ -146,8 +146,8 @@ buildWithLocalState config builderState =
in
( updatedModel, cmd, Nothing )
, subscriptions =
\_ path templateModel sharedModel ->
config.subscriptions NoMetadata path templateModel
\routeParams path templateModel sharedModel ->
config.subscriptions routeParams path templateModel
}
@ -159,12 +159,12 @@ buildWithSharedState :
-> StaticPayload templateStaticData
-> Shared.RenderedBody
-> Shared.PageView templateMsg
, init : NoMetadata -> ( templateModel, Cmd templateMsg )
, update : NoMetadata -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Maybe Shared.SharedMsg )
, subscriptions : NoMetadata -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg
, init : routeParams -> ( templateModel, Cmd templateMsg )
, update : routeParams -> templateMsg -> templateModel -> Shared.Model -> ( templateModel, Cmd templateMsg, Maybe Shared.SharedMsg )
, subscriptions : routeParams -> PagePath Pages.PathKey -> templateModel -> Shared.Model -> Sub templateMsg
}
-> Builder NoMetadata templateStaticData
-> TemplateWithState templateStaticData templateModel templateMsg
-> Builder routeParams templateStaticData
-> TemplateWithState routeParams templateStaticData templateModel templateMsg
buildWithSharedState config builderState =
case builderState of
WithStaticData record ->
@ -182,7 +182,7 @@ withStaticData :
{ staticData : StaticHttp.Request templateStaticData
, head : StaticPayload templateStaticData -> List (Head.Tag Pages.PathKey)
}
-> Builder NoMetadata templateStaticData
-> Builder routeParams templateStaticData
withStaticData { staticData, head } =
WithStaticData
{ staticData = staticData
@ -193,7 +193,7 @@ withStaticData { staticData, head } =
{-| -}
noStaticData :
{ head : StaticPayload () -> List (Head.Tag Pages.PathKey) }
-> Builder NoMetadata ()
-> Builder routeParams ()
noStaticData { head } =
WithStaticData
{ staticData = StaticHttp.succeed ()

View File

@ -35,7 +35,7 @@ type alias Model =
, query : Maybe String
, fragment : Maybe String
}
, metadata : NoMetadata
, metadata : Maybe Route
}
}
@ -67,7 +67,7 @@ type Msg
{ path : PagePath Pages.PathKey
, query : Maybe String
, fragment : Maybe String
, metadata : NoMetadata
, metadata : Maybe Route
}
| ${templates
.map((name) => `Msg${name} Template.${name}.Msg\n`)
@ -76,7 +76,7 @@ type Msg
view :
{ path : PagePath Pages.PathKey
, frontmatter : NoMetadata
, frontmatter : Maybe Route
}
->
StaticHttp.Request
@ -85,10 +85,12 @@ view :
}
view page =
case page.frontmatter of
${[templates[0]]
Nothing ->
StaticHttp.fail "Page not found"
${templates
.map(
(name) =>
`NoMetadata ->
`Just (Route${name} s) ->
StaticHttp.map2
(\\data globalData ->
{ view =
@ -139,7 +141,7 @@ init :
, query : Maybe String
, fragment : Maybe String
}
, metadata : NoMetadata
, metadata : Maybe Route
}
-> ( Model, Cmd Msg )
init currentGlobalModel maybePagePath =
@ -148,21 +150,19 @@ init currentGlobalModel maybePagePath =
currentGlobalModel |> Maybe.map (\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Shared.template.init maybePagePath)
( templateModel, templateCmd ) =
case maybePagePath |> Maybe.map .metadata of
case maybePagePath |> Maybe.andThen .metadata of
Nothing ->
( NotFound, Cmd.none )
Just NoMetadata ->
${[templates[0]]
.map(
(name) => `
Template.${name}.template.init NoMetadata
${templates
.map(
(name) => `Just (Route${name} routeParams) ->
Template.${name}.template.init routeParams
|> Tuple.mapBoth Model${name} (Cmd.map Msg${name})
`
)
.join("\n ")}
)
.join("\n ")}
in
( { global = sharedModel
, page = templateModel
@ -230,10 +230,10 @@ update msg model =
Msg${name} msg_ ->
let
( updatedPageModel, pageCmd, ( newGlobalModel, newGlobalCmd ) ) =
case ( model.page, model.current |> Maybe.map .metadata ) of
( Model${name} pageModel, Just NoMetadata ) ->
case ( model.page, model.current |> Maybe.andThen .metadata ) of
( Model${name} pageModel, Just (Route${name} routeParams) ) ->
Template.${name}.template.update
NoMetadata
routeParams
msg_
pageModel
model.global
@ -263,15 +263,15 @@ type alias SiteConfig =
, manifest : Manifest.Config Pages.PathKey
}
templateSubscriptions : NoMetadata -> PagePath Pages.PathKey -> Model -> Sub Msg
templateSubscriptions metadata path model =
case model.page of
templateSubscriptions : Route -> PagePath Pages.PathKey -> Model -> Sub Msg
templateSubscriptions route path model =
case ( model.page, route ) of
${templates
.map(
(name) => `
Model${name} templateModel ->
( Model${name} templateModel, Route${name} routeParams ) ->
Template.${name}.template.subscriptions
NoMetadata
routeParams
path
templateModel
model.global
@ -281,20 +281,21 @@ templateSubscriptions metadata path model =
.join("\n ")}
NotFound ->
_ ->
Sub.none
mainTemplate { documents, site } =
Pages.Platform.init
{ init = init Nothing
, urlToRoute = urlToRoute
, view = \\_ -> view
, update = update
, subscriptions =
\\metadata path model ->
Sub.batch
[ Shared.template.subscriptions NoMetadata path model.global |> Sub.map MsgGlobal
, templateSubscriptions NoMetadata path model
, templateSubscriptions (RouteBlogIndex {}) path model
]
, documents = documents
, onPageChange = Just OnPageChange

View File

@ -30,17 +30,18 @@ type alias Content =
List ( List String, { extension : String, frontMatter : String, body : Maybe String } )
type alias Program userModel userMsg metadata view pathKey =
Platform.Program Flags (Model userModel userMsg metadata view pathKey) (Msg userMsg metadata view)
type alias Program userModel userMsg route view pathKey =
Platform.Program Flags (Model userModel userMsg route view pathKey) (Msg userMsg view)
mainView :
pathKey
(Url -> route)
-> pathKey
->
(List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -56,10 +57,10 @@ mainView :
)
-> ModelDetails userModel view
-> { title : String, body : Html userMsg }
mainView pathKey pageView model =
mainView urlToRoute pathKey pageView model =
case model.contentCache of
Ok site ->
pageViewOrError pathKey pageView model model.contentCache
pageViewOrError urlToRoute pathKey pageView model model.contentCache
-- TODO these lookup helpers should not need it to be a Result
Err errors ->
@ -84,12 +85,13 @@ normalizeUrl baseUrl url =
pageViewOrError :
pathKey
(Url -> route)
-> pathKey
->
(List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -100,7 +102,7 @@ pageViewOrError :
-> ModelDetails userModel view
-> ContentCache NoMetadata view
-> { title : String, body : Html userMsg }
pageViewOrError pathKey viewFn model cache =
pageViewOrError urlToRoute pathKey viewFn model cache =
let
urls =
{ currentUrl = model.url
@ -113,13 +115,8 @@ pageViewOrError pathKey viewFn model cache =
ContentCache.Parsed NoMetadata body viewResult ->
let
viewFnResult =
{ path = pagePath, frontmatter = NoMetadata }
|> viewFn
(cache
|> Result.map (ContentCache.extractMetadata pathKey)
|> Result.withDefault []
-- TODO handle error better
)
{ path = pagePath, frontmatter = urlToRoute model.url }
|> viewFn []
|> (\request ->
StaticHttpRequest.resolve ApplicationType.Browser request viewResult.staticData
)
@ -178,13 +175,14 @@ pageViewOrError pathKey viewFn model cache =
view :
pathKey
(Url -> route)
-> pathKey
-> Content
->
(List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -193,11 +191,11 @@ view :
}
)
-> ModelDetails userModel view
-> Browser.Document (Msg userMsg NoMetadata view)
view pathKey content viewFn model =
-> Browser.Document (Msg userMsg view)
view urlToRoute pathKey content viewFn model =
let
{ title, body } =
mainView pathKey viewFn model
mainView urlToRoute pathKey viewFn model
in
{ title = title
, body =
@ -255,7 +253,8 @@ contentJsonDecoder =
init :
pathKey
(Url -> route)
-> pathKey
-> String
-> Pages.Document.Document NoMetadata view
-> (Json.Encode.Value -> Cmd Never)
@ -263,7 +262,7 @@ init :
(List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -280,7 +279,7 @@ init :
-> Content
->
(Maybe
{ metadata : NoMetadata
{ metadata : route
, path :
{ path : PagePath pathKey
, query : Maybe String
@ -292,8 +291,8 @@ init :
-> Flags
-> Url
-> Browser.Navigation.Key
-> ( ModelDetails userModel view, Cmd (AppMsg userMsg NoMetadata view) )
init pathKey canonicalSiteUrl document toJsPort viewFn content initUserModel flags url key =
-> ( ModelDetails userModel view, Cmd (AppMsg userMsg view) )
init urlToRoute pathKey canonicalSiteUrl document toJsPort viewFn content initUserModel flags url key =
let
contentCache =
ContentCache.init
@ -358,7 +357,7 @@ init pathKey canonicalSiteUrl document toJsPort viewFn content initUserModel fla
, query = url.query
, fragment = url.fragment
}
, metadata = NoMetadata
, metadata = urlToRoute url
}
)
maybePagePath
@ -429,12 +428,12 @@ encodeHeads allRoutes canonicalSiteUrl currentPagePath head =
]
type Msg userMsg metadata view
= AppMsg (AppMsg userMsg metadata view)
type Msg userMsg view
= AppMsg (AppMsg userMsg view)
| CliMsg Pages.Internal.Platform.Cli.Msg
type AppMsg userMsg metadata view
type AppMsg userMsg view
= LinkClicked Browser.UrlRequest
| UrlChanged Url.Url
| UserMsg userMsg
@ -468,14 +467,15 @@ type Phase
update :
Content
(Url.Url -> route)
-> Content
-> List String
-> String
->
(List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -489,17 +489,17 @@ update :
({ path : PagePath pathKey
, query : Maybe String
, fragment : Maybe String
, metadata : NoMetadata
, metadata : route
}
-> userMsg
)
-> (Json.Encode.Value -> Cmd Never)
-> Pages.Document.Document NoMetadata view
-> (userMsg -> userModel -> ( userModel, Cmd userMsg ))
-> Msg userMsg NoMetadata view
-> Msg userMsg view
-> ModelDetails userModel view
-> ( ModelDetails userModel view, Cmd (AppMsg userMsg NoMetadata view) )
update content allRoutes canonicalSiteUrl viewFunction pathKey maybeOnPageChangeMsg toJsPort document userUpdate msg model =
-> ( ModelDetails userModel view, Cmd (AppMsg userMsg view) )
update urlToRoute content allRoutes canonicalSiteUrl viewFunction pathKey maybeOnPageChangeMsg toJsPort document userUpdate msg model =
case msg of
AppMsg appMsg ->
case appMsg of
@ -569,7 +569,7 @@ update content allRoutes canonicalSiteUrl viewFunction pathKey maybeOnPageChange
Just ( pagePath, entry ) ->
case entry of
ContentCache.Parsed frontmatter body viewResult ->
headFn pagePath frontmatter viewResult.staticData
headFn pagePath (urlToRoute model.url) viewResult.staticData
|> Result.map .head
|> Result.toMaybe
|> Maybe.map (encodeHeads allRoutes canonicalSiteUrl model.url.path)
@ -644,7 +644,7 @@ update content allRoutes canonicalSiteUrl viewFunction pathKey maybeOnPageChange
{ path = urlToPagePath pathKey url model.baseUrl
, query = url.query
, fragment = url.fragment
, metadata = NoMetadata
, metadata = urlToRoute model.url
}
)
model.userModel
@ -700,16 +700,17 @@ application :
, query : Maybe String
, fragment : Maybe String
}
, metadata : NoMetadata
, metadata : route
}
-> ( userModel, Cmd userMsg )
, urlToRoute : Url.Url -> route
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : NoMetadata -> PagePath pathKey -> userModel -> Sub userMsg
, view :
List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -744,25 +745,25 @@ application :
({ path : PagePath pathKey
, query : Maybe String
, fragment : Maybe String
, metadata : NoMetadata
, metadata : route
}
-> userMsg
)
}
-- -> Program userModel userMsg metadata view
-> Platform.Program Flags (Model userModel userMsg NoMetadata view pathKey) (Msg userMsg NoMetadata view)
-> Platform.Program Flags (Model userModel userMsg route view pathKey) (Msg userMsg view)
application config =
Browser.application
{ init =
\flags url key ->
init config.pathKey config.canonicalSiteUrl config.document config.toJsPort config.view config.content config.init flags url key
init config.urlToRoute config.pathKey config.canonicalSiteUrl config.document config.toJsPort config.view config.content config.init flags url key
|> Tuple.mapFirst Model
|> Tuple.mapSecond (Cmd.map AppMsg)
, view =
\outerModel ->
case outerModel of
Model model ->
view config.pathKey config.content config.view model
view config.urlToRoute config.pathKey config.content config.view model
CliModel _ ->
{ title = "Error"
@ -790,7 +791,7 @@ application config =
|> List.map Tuple.first
|> List.map (String.join "/")
in
update config.content allRoutes config.canonicalSiteUrl config.view config.pathKey config.onPageChange config.toJsPort config.document userUpdate msg model
update config.urlToRoute config.content allRoutes config.canonicalSiteUrl config.view config.pathKey config.onPageChange config.toJsPort config.document userUpdate msg model
|> Tuple.mapFirst Model
|> Tuple.mapSecond (Cmd.map AppMsg)
@ -859,16 +860,17 @@ cliApplication :
, query : Maybe String
, fragment : Maybe String
}
, metadata : NoMetadata
, metadata : route
}
-> ( userModel, Cmd userMsg )
, urlToRoute : Url.Url -> route
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : NoMetadata -> PagePath pathKey -> userModel -> Sub userMsg
, view :
List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -903,12 +905,12 @@ cliApplication :
({ path : PagePath pathKey
, query : Maybe String
, fragment : Maybe String
, metadata : NoMetadata
, metadata : route
}
-> userMsg
)
}
-> Program userModel userMsg NoMetadata view pathKey
-> Program userModel userMsg route view pathKey
cliApplication =
Pages.Internal.Platform.Cli.cliApplication CliMsg
(\msg ->

View File

@ -64,7 +64,7 @@ type Msg
| Continue
type alias Config pathKey userMsg userModel view =
type alias Config pathKey userMsg userModel view route =
{ init :
Maybe
{ path :
@ -72,16 +72,17 @@ type alias Config pathKey userMsg userModel view =
, query : Maybe String
, fragment : Maybe String
}
, metadata : NoMetadata
, metadata : route
}
-> ( userModel, Cmd userMsg )
, urlToRoute : Url.Url -> route
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : NoMetadata -> PagePath pathKey -> userModel -> Sub userMsg
, view :
List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -116,7 +117,7 @@ type alias Config pathKey userMsg userModel view =
({ path : PagePath pathKey
, query : Maybe String
, fragment : Maybe String
, metadata : NoMetadata
, metadata : route
}
-> userMsg
)
@ -128,7 +129,7 @@ cliApplication :
-> (msg -> Maybe Msg)
-> (Model pathKey -> model)
-> (model -> Maybe (Model pathKey))
-> Config pathKey userMsg userModel view
-> Config pathKey userMsg userModel view route
-> Platform.Program Flags model msg
cliApplication cliMsgConstructor narrowMsg toModel fromModel config =
let
@ -233,7 +234,7 @@ asJsonView x =
Json.Encode.string "REPLACE_ME_WITH_JSON_STRINGIFY"
perform : Config pathKey userMsg userModel view -> (Msg -> msg) -> (Json.Encode.Value -> Cmd Never) -> Effect pathKey -> Cmd msg
perform : Config pathKey userMsg userModel view route -> (Msg -> msg) -> (Json.Encode.Value -> Cmd Never) -> Effect pathKey -> Cmd msg
perform config cliMsgConstructor toJsPort effect =
case effect of
Effect.NoEffect ->
@ -376,7 +377,7 @@ init :
(Model pathKey -> model)
-> ContentCache.ContentCache NoMetadata view
-> Result (List BuildError) (List ( PagePath pathKey, NoMetadata ))
-> Config pathKey userMsg userModel view
-> Config pathKey userMsg userModel view route
-> Decode.Value
-> ( model, Effect pathKey )
init toModel contentCache siteMetadata config flags =
@ -413,18 +414,28 @@ init toModel contentCache siteMetadata config flags =
--)
initLegacy :
{ a | secrets : SecretsDict, mode : Mode, staticHttpCache : Dict String (Maybe String) }
-> (Model pathKey -> model)
-> ContentCache.ContentCache NoMetadata view
-> Result (List BuildError) (List ( PagePath pathKey, NoMetadata ))
-> Config pathKey userMsg userModel view route
-> f
-> ( model, Effect pathKey )
initLegacy { secrets, mode, staticHttpCache } toModel contentCache siteMetadata config flags =
let
staticRoutes : List ( PagePath pathKey, route )
staticRoutes =
-- TODO need to get the list of static routes here, like getStaticPaths
[]
in
case contentCache of
Ok _ ->
case ContentCache.pagesWithErrors contentCache of
[] ->
let
requests =
Result.andThen
(\metadata ->
staticResponseForPage metadata config.view
)
siteMetadata
staticResponseForPage staticRoutes config.view
staticResponses : StaticResponses
staticResponses =
@ -443,11 +454,7 @@ initLegacy { secrets, mode, staticHttpCache } toModel contentCache siteMetadata
pageErrors ->
let
requests =
Result.andThen
(\metadata ->
staticResponseForPage metadata config.view
)
siteMetadata
staticResponseForPage staticRoutes config.view
staticResponses : StaticResponses
staticResponses =
@ -492,7 +499,7 @@ initLegacy { secrets, mode, staticHttpCache } toModel contentCache siteMetadata
updateAndSendPortIfDone :
ContentCache.ContentCache NoMetadata view
-> Config pathKey userMsg userModel view
-> Config pathKey userMsg userModel view route
-> Result (List BuildError) (List ( PagePath pathKey, NoMetadata ))
-> Model pathKey
-> (Model pathKey -> model)
@ -526,7 +533,7 @@ drop1 model =
update :
ContentCache.ContentCache NoMetadata view
-> Result (List BuildError) (List ( PagePath pathKey, NoMetadata ))
-> Config pathKey userMsg userModel view
-> Config pathKey userMsg userModel view route
-> Msg
-> Model pathKey
-> ( Model pathKey, Effect pathKey )
@ -721,7 +728,7 @@ update contentCache siteMetadata config msg model =
nextStepToEffect :
ContentCache.ContentCache NoMetadata view
-> Config pathKey userMsg userModel view
-> Config pathKey userMsg userModel view route
-> Model pathKey
-> StaticResponses.NextStep pathKey
-> ( Model pathKey, Effect pathKey )
@ -830,7 +837,7 @@ nextStepToEffect contentCache config model nextStep =
sendSinglePageProgress :
ToJsSuccessPayload pathKey
-> Result (List BuildError) (List ( PagePath pathKey, NoMetadata ))
-> Config pathKey userMsg userModel view
-> Config pathKey userMsg userModel view route
-> ContentCache NoMetadata view
-> Model pathKey
-> ( PagePath pathKey, NoMetadata )
@ -872,9 +879,9 @@ sendSinglePageProgress toJsPayload siteMetadata config contentCache model =
urls
{ body = "", staticData = model.allRawResponses }
currentPage : { path : PagePath pathKey, frontmatter : NoMetadata }
currentPage : { path : PagePath pathKey, frontmatter : route }
currentPage =
{ path = page, frontmatter = NoMetadata.NoMetadata }
{ path = page, frontmatter = config.urlToRoute currentUrl }
pageModel : userModel
pageModel =
@ -885,7 +892,7 @@ sendSinglePageProgress toJsPayload siteMetadata config contentCache model =
, query = Nothing
, fragment = Nothing
}
, metadata = NoMetadata.NoMetadata
, metadata = currentPage.frontmatter
}
)
|> Tuple.first
@ -894,7 +901,7 @@ sendSinglePageProgress toJsPayload siteMetadata config contentCache model =
{ protocol = Url.Https
, host = config.canonicalSiteUrl
, port_ = Nothing
, path = currentPage.path |> PagePath.toString
, path = page |> PagePath.toString
, query = Nothing
, fragment = Nothing
}
@ -977,12 +984,12 @@ sendProgress singlePage =
staticResponseForPage :
List ( PagePath pathKey, NoMetadata )
List ( PagePath pathKey, route )
->
(List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttpRequest.Request
@ -1002,14 +1009,17 @@ staticResponseForPage :
)
)
staticResponseForPage siteMetadata viewFn =
-- TODO need all Routes here, and their page paths
-- need to start with hardcoding the static URLs
-- eventually, getStaticPaths equivalent
siteMetadata
|> List.map
(\( pagePath, frontmatter ) ->
(\( pagePath, route ) ->
let
thing =
viewFn siteMetadata
viewFn []
{ path = pagePath
, frontmatter = frontmatter
, frontmatter = route
}
in
Ok ( pagePath, thing )

View File

@ -3,6 +3,7 @@ module Pages.Internal.Platform.StaticResponses exposing (NextStep(..), StaticRes
import BuildError exposing (BuildError)
import Dict exposing (Dict)
import Dict.Extra
import NoMetadata exposing (NoMetadata)
import Pages.Internal.ApplicationType as ApplicationType
import Pages.Internal.Platform.Mode as Mode exposing (Mode)
import Pages.Internal.Platform.ToJsPayload as ToJsPayload exposing (ToJsPayload)
@ -50,7 +51,8 @@ init :
->
StaticHttp.Request
(List
(Result String
(Result
String
{ path : List String
, content : String
}
@ -190,13 +192,14 @@ nextStep :
, generateFiles :
List
{ path : PagePath pathKey
, frontmatter : metadata
, frontmatter : NoMetadata
, body : String
}
->
StaticHttp.Request
(List
(Result String
(Result
String
{ path : List String
, content : String
}
@ -214,37 +217,7 @@ nextStep :
nextStep config allSiteMetadata siteMetadata mode secrets allRawResponses errors (StaticResponses staticResponses) =
let
metadataForGenerateFiles =
allSiteMetadata
|> Result.withDefault []
|> List.map
-- TODO extract helper function that processes next step *for a single page* at a time
(\( pagePath, metadata ) ->
let
contentForPage =
config.content
|> List.filterMap
(\( path, { body } ) ->
let
pagePathToGenerate =
PagePath.toString pagePath
currentContentPath =
String.join "/" path
in
if pagePathToGenerate == currentContentPath then
Just body
else
Nothing
)
|> List.head
|> Maybe.andThen identity
in
{ path = pagePath
, frontmatter = metadata
, body = contentForPage |> Maybe.withDefault ""
}
)
[]
generatedFiles : List (Result String { path : List String, content : String })
generatedFiles =

View File

@ -73,6 +73,7 @@ import Pages.Internal.Platform
import Pages.Manifest
import Pages.PagePath exposing (PagePath)
import Pages.StaticHttp as StaticHttp
import Url
{-| You can [`init`](#init) a `Builder`, and then turn it to a [`Program`](#Program) with [`toProgram`](#toProgram).
@ -80,7 +81,7 @@ import Pages.StaticHttp as StaticHttp
That gives you the basic options, then you can [include optional configuration](#additional-application-config).
-}
type Builder pathKey model msg metadata view
type Builder pathKey model msg route view
= Builder
{ init :
Maybe
@ -89,16 +90,17 @@ type Builder pathKey model msg metadata view
, query : Maybe String
, fragment : Maybe String
}
, metadata : NoMetadata
, metadata : route
}
-> ( model, Cmd msg )
, urlToRoute : Url.Url -> route
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : NoMetadata -> PagePath pathKey -> model -> Sub msg
, view :
List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -128,7 +130,7 @@ type Builder pathKey model msg metadata view
({ path : PagePath pathKey
, query : Maybe String
, fragment : Maybe String
, metadata : NoMetadata
, metadata : route
}
-> msg
)
@ -172,7 +174,7 @@ init :
, query : Maybe String
, fragment : Maybe String
}
, metadata : NoMetadata
, metadata : route
}
-> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
@ -180,7 +182,7 @@ init :
List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -199,18 +201,20 @@ init :
({ path : PagePath pathKey
, query : Maybe String
, fragment : Maybe String
, metadata : NoMetadata
, metadata : route
}
-> msg
)
, manifest : Pages.Manifest.Config pathKey
, canonicalSiteUrl : String
, internals : Pages.Internal.Internal pathKey
, urlToRoute : Url.Url -> route
}
-> Builder pathKey model msg NoMetadata view
-> Builder pathKey model msg route view
init config =
Builder
{ init = config.init
, urlToRoute = config.urlToRoute
, view = config.view
, update = config.update
, subscriptions = config.subscriptions
@ -227,8 +231,8 @@ init config =
-}
withGlobalHeadTags :
List (Head.Tag pathKey)
-> Builder pathKey model msg NoMetadata view
-> Builder pathKey model msg NoMetadata view
-> Builder pathKey model msg route view
-> Builder pathKey model msg route view
withGlobalHeadTags globalHeadTags (Builder config) =
Builder
{ config
@ -290,8 +294,8 @@ withFileGenerator :
)
)
)
-> Builder pathKey model msg NoMetadata view
-> Builder pathKey model msg NoMetadata view
-> Builder pathKey model msg route view
-> Builder pathKey model msg route view
withFileGenerator generateFiles (Builder config) =
Builder
{ config
@ -305,10 +309,11 @@ withFileGenerator generateFiles (Builder config) =
{-| When you're done with your builder pipeline, you complete it with `Pages.Platform.toProgram`.
-}
toProgram : Builder pathKey model msg NoMetadata view -> Program model msg NoMetadata view pathKey
toProgram : Builder pathKey model msg route view -> Program model msg route view pathKey
toProgram (Builder config) =
application
{ init = config.init
, urlToRoute = config.urlToRoute
, view = config.view
, update = config.update
, subscriptions = config.subscriptions
@ -329,16 +334,17 @@ application :
, query : Maybe String
, fragment : Maybe String
}
, metadata : NoMetadata
, metadata : route
}
-> ( model, Cmd msg )
, urlToRoute : Url.Url -> route
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : NoMetadata -> PagePath pathKey -> model -> Sub msg
, view :
List ( PagePath pathKey, NoMetadata )
->
{ path : PagePath pathKey
, frontmatter : NoMetadata
, frontmatter : route
}
->
StaticHttp.Request
@ -368,14 +374,14 @@ application :
({ path : PagePath pathKey
, query : Maybe String
, fragment : Maybe String
, metadata : NoMetadata
, metadata : route
}
-> msg
)
, canonicalSiteUrl : String
, internals : Pages.Internal.Internal pathKey
}
-> Program model msg NoMetadata view pathKey
-> Program model msg route view pathKey
application config =
(case config.internals.applicationType of
Pages.Internal.Browser ->
@ -386,6 +392,7 @@ application config =
)
<|
{ init = config.init
, urlToRoute = config.urlToRoute
, view = config.view
, update = config.update
, subscriptions = config.subscriptions
@ -403,8 +410,8 @@ application config =
{-| The `Program` type for an `elm-pages` app.
-}
type alias Program model msg metadata view pathKey =
Pages.Internal.Platform.Program model msg metadata view pathKey
type alias Program model msg route view pathKey =
Pages.Internal.Platform.Program model msg route view pathKey
{-| -}