mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-30 23:06:10 +03:00
Wire through (Maybe (PagePath pathKey)) as init argument.
This commit is contained in:
parent
fcc3661909
commit
431b350858
@ -432,22 +432,23 @@ lookup pathKey content url =
|
||||
|
||||
|
||||
lookupMetadata :
|
||||
ContentCache metadata view
|
||||
pathKey
|
||||
-> ContentCache metadata view
|
||||
-> Url
|
||||
-> Maybe metadata
|
||||
lookupMetadata content url =
|
||||
lookup () content url
|
||||
-> Maybe ( PagePath pathKey, metadata )
|
||||
lookupMetadata pathKey content url =
|
||||
lookup pathKey content url
|
||||
|> Maybe.map
|
||||
(\( pagePath, entry ) ->
|
||||
case entry of
|
||||
NeedContent _ metadata ->
|
||||
metadata
|
||||
( pagePath, metadata )
|
||||
|
||||
Unparsed _ metadata _ ->
|
||||
metadata
|
||||
( pagePath, metadata )
|
||||
|
||||
Parsed metadata _ ->
|
||||
metadata
|
||||
( pagePath, metadata )
|
||||
)
|
||||
|
||||
|
||||
|
@ -177,28 +177,37 @@ init :
|
||||
-> (Json.Encode.Value -> Cmd (Msg userMsg metadata view))
|
||||
-> (metadata -> List (Head.Tag pathKey))
|
||||
-> Content
|
||||
-> ( userModel, Cmd userMsg )
|
||||
-> (Maybe (PagePath pathKey) -> ( userModel, Cmd userMsg ))
|
||||
-> Flags
|
||||
-> Url
|
||||
-> Browser.Navigation.Key
|
||||
-> ( ModelDetails userModel metadata view, Cmd (Msg userMsg metadata view) )
|
||||
init pathKey canonicalSiteUrl document toJsPort head content initUserModel flags url key =
|
||||
let
|
||||
( userModel, userCmd ) =
|
||||
initUserModel
|
||||
|
||||
contentCache =
|
||||
ContentCache.init document content
|
||||
in
|
||||
case contentCache of
|
||||
Ok okCache ->
|
||||
let
|
||||
( userModel, userCmd ) =
|
||||
initUserModel maybePagePath
|
||||
|
||||
( maybePagePath, maybeMetadata ) =
|
||||
case ContentCache.lookupMetadata pathKey (Ok okCache) url of
|
||||
Just ( pagePath, metadata ) ->
|
||||
( Just pagePath, Just metadata )
|
||||
|
||||
Nothing ->
|
||||
( Nothing, Nothing )
|
||||
in
|
||||
( { key = key
|
||||
, url = url
|
||||
, userModel = userModel
|
||||
, contentCache = contentCache
|
||||
}
|
||||
, Cmd.batch
|
||||
([ ContentCache.lookupMetadata (Ok okCache) url
|
||||
([ maybeMetadata
|
||||
|> Maybe.map head
|
||||
|> Maybe.map (encodeHeads canonicalSiteUrl url.path)
|
||||
|> Maybe.map toJsPort
|
||||
@ -213,6 +222,10 @@ init pathKey canonicalSiteUrl document toJsPort head content initUserModel flags
|
||||
)
|
||||
|
||||
Err _ ->
|
||||
let
|
||||
( userModel, userCmd ) =
|
||||
initUserModel Nothing
|
||||
in
|
||||
( { key = key
|
||||
, url = url
|
||||
, userModel = userModel
|
||||
@ -332,7 +345,7 @@ type alias Parser metadata view =
|
||||
|
||||
|
||||
application :
|
||||
{ init : ( userModel, Cmd userMsg )
|
||||
{ init : Maybe (PagePath pathKey) -> ( userModel, Cmd userMsg )
|
||||
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
||||
, subscriptions : userModel -> Sub userMsg
|
||||
, view : userModel -> List ( PagePath pathKey, metadata ) -> Page metadata view pathKey -> { title : String, body : Html userMsg }
|
||||
@ -385,7 +398,7 @@ application config =
|
||||
|
||||
|
||||
cliApplication :
|
||||
{ init : ( userModel, Cmd userMsg )
|
||||
{ init : Maybe (PagePath pathKey) -> ( userModel, Cmd userMsg )
|
||||
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
||||
, subscriptions : userModel -> Sub userMsg
|
||||
, view : userModel -> List ( PagePath pathKey, metadata ) -> Page metadata view pathKey -> { title : String, body : Html userMsg }
|
||||
@ -444,4 +457,3 @@ encodeErrors errors =
|
||||
|> Json.Encode.dict
|
||||
(\path -> "/" ++ String.join "/" path)
|
||||
(\errorsForPath -> Json.Encode.string errorsForPath)
|
||||
|
||||
|
@ -78,8 +78,8 @@ type alias Model =
|
||||
{}
|
||||
|
||||
|
||||
init : ( Model, Cmd Msg )
|
||||
init =
|
||||
init : Maybe (PagePath Pages.PathKey) -> ( Model, Cmd Msg )
|
||||
init maybePagePath =
|
||||
( Model, Cmd.none )
|
||||
|
||||
|
||||
|
@ -89,7 +89,7 @@ port toJsPort : Json.Encode.Value -> Cmd msg
|
||||
|
||||
|
||||
application :
|
||||
{ init : ( userModel, Cmd userMsg )
|
||||
{ init : Maybe (PagePath PathKey) -> ( userModel, Cmd userMsg )
|
||||
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
||||
, subscriptions : userModel -> Sub userMsg
|
||||
, view : userModel -> List ( PagePath PathKey, metadata ) -> Page metadata view PathKey -> { title : String, body : Html userMsg }
|
||||
@ -169,7 +169,7 @@ port toJsPort : Json.Encode.Value -> Cmd msg
|
||||
|
||||
|
||||
application :
|
||||
{ init : ( userModel, Cmd userMsg )
|
||||
{ init : Maybe (PagePath PathKey) -> ( userModel, Cmd userMsg )
|
||||
, update : userMsg -> userModel -> ( userModel, Cmd userMsg )
|
||||
, subscriptions : userModel -> Sub userMsg
|
||||
, view : userModel -> List ( PagePath PathKey, metadata ) -> Page metadata view PathKey -> { title : String, body : Html userMsg }
|
||||
|
Loading…
Reference in New Issue
Block a user