Wire in all Routes in SiteConfig.

This commit is contained in:
Dillon Kearns 2021-04-13 18:43:31 -07:00
parent 713ff07634
commit 423e6de328
7 changed files with 121 additions and 90 deletions

View File

@ -9,18 +9,20 @@ import Pages.ImagePath as ImagePath exposing (ImagePath)
import Pages.Manifest as Manifest
import Pages.Manifest.Category
import Pages.PagePath as PagePath
import Pages.SiteConfig exposing (SiteConfig)
import Pages.StaticHttp as StaticHttp
import Route exposing (Route)
import SiteConfig exposing (SiteConfig)
config : SiteConfig StaticData
config =
{ staticData = staticData
, canonicalUrl = canonicalUrl
, manifest = manifest
, head = head
, generateFiles = generateFiles
}
\routes ->
{ staticData = staticData
, canonicalUrl = canonicalUrl
, manifest = manifest
, head = head
, generateFiles = generateFiles
}

View File

@ -0,0 +1,8 @@
module SiteConfig exposing (SiteConfig)
import Pages.SiteConfig
import Route exposing (Route)
type alias SiteConfig staticData =
Pages.SiteConfig.SiteConfig (Maybe Route) staticData

View File

@ -321,30 +321,7 @@ main =
, urlToRoute = Route.urlToRoute
, routeToPath = Route.routeToPath
, site = Site.config
, getStaticRoutes =
StaticHttp.combine
[ StaticHttp.succeed
[ ${templates
.filter((name) => !isParameterizedRoute(name))
.map(
(name) => `Route.${routeHelpers.routeVariant(name)} {}`
)
.join("\n , ")}
]
, ${templates
.filter((name) => isParameterizedRoute(name))
.map(
(name) =>
`Template.${moduleName(
name
)}.template.staticRoutes |> StaticHttp.map (List.map Route.${pathNormalizedName(
name
)})`
)
.join("\n , ")}
]
|> StaticHttp.map List.concat
|> StaticHttp.map (List.map Just)
, getStaticRoutes = getStaticRoutes
, view = view
, update = update
, subscriptions =
@ -357,17 +334,54 @@ main =
, canonicalSiteUrl = "TODO"
, toJsPort = toJsPort
, fromJsPort = fromJsPort identity
, generateFiles = StaticHttp.map2 (::) manifestGenerator Site.config.generateFiles
, generateFiles =
getStaticRoutes
|> StaticHttp.andThen
(\\resolvedStaticRoutes ->
StaticHttp.map2 (::)
(manifestGenerator
resolvedStaticRoutes
)
(Site.config
resolvedStaticRoutes
|> .generateFiles
)
)
}
manifestGenerator : StaticHttp.Request (Result anyError { path : List String, content : String })
manifestGenerator =
Site.config.staticData
getStaticRoutes =
StaticHttp.combine
[ StaticHttp.succeed
[ ${templates
.filter((name) => !isParameterizedRoute(name))
.map((name) => `Route.${routeHelpers.routeVariant(name)} {}`)
.join("\n , ")}
]
, ${templates
.filter((name) => isParameterizedRoute(name))
.map(
(name) =>
`Template.${moduleName(
name
)}.template.staticRoutes |> StaticHttp.map (List.map Route.${pathNormalizedName(
name
)})`
)
.join("\n , ")}
]
|> StaticHttp.map List.concat
|> StaticHttp.map (List.map Just)
manifestGenerator : List ( Maybe Route ) -> StaticHttp.Request (Result anyError { path : List String, content : String })
manifestGenerator resolvedRoutes =
Site.config resolvedRoutes
|> .staticData
|> StaticHttp.map
(\\data ->
Site.config.manifest data
|> manifestToFile (Site.config.canonicalUrl data)
(Site.config resolvedRoutes |> .manifest) data
|> manifestToFile ((Site.config resolvedRoutes |> .canonicalUrl) data)
)
@ -383,6 +397,7 @@ manifestToFile resolvedCanonicalUrl manifestConfig =
)
port toJsPort : Json.Encode.Value -> Cmd msg
port fromJsPort : (Json.Decode.Value -> msg) -> Sub msg

View File

@ -520,7 +520,7 @@ application :
, urlToRoute : Url -> route
, routeToPath : route -> List String
, getStaticRoutes : StaticHttp.Request (List route)
, site : SiteConfig staticData
, site : SiteConfig route staticData
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : PagePath -> userModel -> Sub userMsg
, view :
@ -671,7 +671,7 @@ cliApplication :
, getStaticRoutes : StaticHttp.Request (List route)
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : PagePath -> userModel -> Sub userMsg
, site : SiteConfig staticData
, site : SiteConfig route staticData
, view :
{ path : PagePath
, frontmatter : route

View File

@ -75,7 +75,7 @@ type alias Config userMsg userModel route siteStaticData =
, getStaticRoutes : StaticHttp.Request (List route)
, urlToRoute : Url -> route
, routeToPath : route -> List String
, site : SiteConfig siteStaticData
, site : SiteConfig route siteStaticData
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
, subscriptions : PagePath -> userModel -> Sub userMsg
, view :

View File

@ -37,7 +37,7 @@ init :
{ config
| view : { path : PagePath, frontmatter : route } -> StaticHttp.Request b
, getStaticRoutes : StaticHttp.Request (List route)
, site : SiteConfig siteStaticData
, site : SiteConfig route siteStaticData
, generateFiles :
StaticHttp.Request
(List
@ -52,10 +52,14 @@ init :
-> StaticResponses
init config =
NotFetched
(StaticHttp.map3 (\_ _ _ -> ())
config.getStaticRoutes
(StaticHttp.map2 (\_ _ -> ())
(config.getStaticRoutes
|> StaticHttp.andThen
(\resolvedRoutes ->
config.site resolvedRoutes |> .staticData
)
)
config.generateFiles
config.site.staticData
)
Dict.empty
|> GettingInitialData
@ -152,7 +156,7 @@ nextStep :
| getStaticRoutes : StaticHttp.Request (List route)
, routeToPath : route -> List String
, view : { path : PagePath, frontmatter : route } -> StaticHttp.Request b
, site : SiteConfig siteStaticData
, site : SiteConfig route siteStaticData
, generateFiles :
StaticHttp.Request
(List
@ -423,34 +427,34 @@ nextStep config mode secrets allRawResponses errors staticResponses_ maybeRoutes
)
StaticResponses _ ->
let
siteStaticData =
StaticHttpRequest.resolve ApplicationType.Cli
config.site.staticData
(allRawResponses |> Dict.Extra.filterMap (\_ value -> Just value))
|> Result.mapError (StaticHttpRequest.toBuildError "Site.elm")
in
case siteStaticData of
Err siteStaticDataError ->
( staticResponses_
, ToJsPayload.toJsPayload
(encode allRawResponses mode staticResponses)
generatedOkayFiles
allRawResponses
(siteStaticDataError :: allErrors)
|> Finish
)
Ok okSiteStaticData ->
( staticResponses_
, ToJsPayload.toJsPayload
(encode allRawResponses mode staticResponses)
generatedOkayFiles
allRawResponses
allErrors
-- TODO send all global head tags on initial call
|> Finish
)
--let
-- siteStaticData =
-- StaticHttpRequest.resolve ApplicationType.Cli
-- config.site.staticData
-- (allRawResponses |> Dict.Extra.filterMap (\_ value -> Just value))
-- |> Result.mapError (StaticHttpRequest.toBuildError "Site.elm")
--in
--case siteStaticData of
-- Err siteStaticDataError ->
-- ( staticResponses_
-- , ToJsPayload.toJsPayload
-- (encode allRawResponses mode staticResponses)
-- generatedOkayFiles
-- allRawResponses
-- (siteStaticDataError :: allErrors)
-- |> Finish
-- )
--
-- Ok okSiteStaticData ->
( staticResponses_
, ToJsPayload.toJsPayload
(encode allRawResponses mode staticResponses)
generatedOkayFiles
allRawResponses
allErrors
-- TODO send all global head tags on initial call
|> Finish
)
performStaticHttpRequests :

View File

@ -5,21 +5,23 @@ import Pages.Manifest
import Pages.StaticHttp as StaticHttp
type alias SiteConfig staticData =
{ staticData : StaticHttp.Request staticData
, canonicalUrl : staticData -> String
, manifest : staticData -> Pages.Manifest.Config
, head :
staticData
-> List Head.Tag
, generateFiles :
StaticHttp.Request
(List
(Result
String
{ path : List String
, content : String
}
type alias SiteConfig route staticData =
List route
->
{ staticData : StaticHttp.Request staticData
, canonicalUrl : staticData -> String
, manifest : staticData -> Pages.Manifest.Config
, head :
staticData
-> List Head.Tag
, generateFiles :
StaticHttp.Request
(List
(Result
String
{ path : List String
, content : String
}
)
)
)
}
}