Replace some PagePath references with new Path API.

This commit is contained in:
Dillon Kearns 2021-05-23 15:37:47 -07:00
parent 5e8f7951d6
commit 3fc5abace9
4 changed files with 29 additions and 30 deletions

View File

@ -30,7 +30,6 @@ import Pages.Internal.Platform.Mode as Mode exposing (Mode)
import Pages.Internal.Platform.StaticResponses as StaticResponses exposing (StaticResponses) import Pages.Internal.Platform.StaticResponses as StaticResponses exposing (StaticResponses)
import Pages.Internal.Platform.ToJsPayload as ToJsPayload exposing (ToJsSuccessPayload) import Pages.Internal.Platform.ToJsPayload as ToJsPayload exposing (ToJsSuccessPayload)
import Pages.Internal.StaticHttpBody as StaticHttpBody import Pages.Internal.StaticHttpBody as StaticHttpBody
import Pages.PagePath as PagePath exposing (PagePath)
import Pages.ProgramConfig exposing (ProgramConfig) import Pages.ProgramConfig exposing (ProgramConfig)
import Pages.StaticHttpRequest as StaticHttpRequest import Pages.StaticHttpRequest as StaticHttpRequest
import Path exposing (Path) import Path exposing (Path)
@ -52,8 +51,8 @@ type alias Model route =
, allRawResponses : Dict String (Maybe String) , allRawResponses : Dict String (Maybe String)
, mode : Mode , mode : Mode
, pendingRequests : List { masked : RequestDetails, unmasked : RequestDetails } , pendingRequests : List { masked : RequestDetails, unmasked : RequestDetails }
, unprocessedPages : List ( PagePath, route ) , unprocessedPages : List ( Path, route )
, staticRoutes : Maybe (List ( PagePath, route )) , staticRoutes : Maybe (List ( Path, route ))
, maybeRequestJson : RenderRequest route , maybeRequestJson : RenderRequest route
} }
@ -696,7 +695,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
newRoutes newRoutes
|> List.map |> List.map
(\route -> (\route ->
( PagePath.build (config.routeToPath route) ( Path.join (config.routeToPath route)
, route , route
) )
) )
@ -711,7 +710,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
newRoutes newRoutes
|> List.map |> List.map
(\route -> (\route ->
( PagePath.build (config.routeToPath route) ( Path.join (config.routeToPath route)
, route , route
) )
) )
@ -870,7 +869,7 @@ sendSinglePageProgress :
ToJsSuccessPayload ToJsSuccessPayload
-> ProgramConfig userMsg userModel route siteData pageData sharedData -> ProgramConfig userMsg userModel route siteData pageData sharedData
-> Model route -> Model route
-> ( PagePath, route ) -> ( Path, route )
-> Effect -> Effect
sendSinglePageProgress toJsPayload config model = sendSinglePageProgress toJsPayload config model =
\( page, route ) -> \( page, route ) ->
@ -932,7 +931,7 @@ sendSinglePageProgress toJsPayload config model =
{ protocol = Url.Https { protocol = Url.Https
, host = config.site allRoutes |> .canonicalUrl , host = config.site allRoutes |> .canonicalUrl
, port_ = Nothing , port_ = Nothing
, path = page |> PagePath.toString , path = page |> Path.toRelative
, query = Nothing , query = Nothing
, fragment = Nothing , fragment = Nothing
} }
@ -940,12 +939,12 @@ sendSinglePageProgress toJsPayload config model =
staticData : Dict String String staticData : Dict String String
staticData = staticData =
toJsPayload.pages toJsPayload.pages
|> Dict.get (PagePath.toString page) |> Dict.get (Path.toRelative page)
|> Maybe.withDefault Dict.empty |> Maybe.withDefault Dict.empty
currentPage : { path : Path, frontmatter : route } currentPage : { path : Path, frontmatter : route }
currentPage = currentPage =
{ path = page |> PagePath.toPath |> Path.join, frontmatter = config.urlToRoute currentUrl } { path = page, frontmatter = config.urlToRoute currentUrl }
pageDataResult : Result BuildError pageData pageDataResult : Result BuildError pageData
pageDataResult = pageDataResult =
@ -970,10 +969,10 @@ sendSinglePageProgress toJsPayload config model =
in in
case Result.map3 (\a b c -> ( a, b, c )) pageFoundResult renderedResult siteDataResult of case Result.map3 (\a b c -> ( a, b, c )) pageFoundResult renderedResult siteDataResult of
Ok ( pageFound, rendered, siteData ) -> Ok ( pageFound, rendered, siteData ) ->
{ route = page |> PagePath.toString { route = page |> Path.toRelative
, contentJson = , contentJson =
toJsPayload.pages toJsPayload.pages
|> Dict.get (PagePath.toString page) |> Dict.get (Path.toRelative page)
|> Maybe.withDefault Dict.empty |> Maybe.withDefault Dict.empty
, html = rendered.view , html = rendered.view
, errors = [] , errors = []
@ -994,12 +993,12 @@ sendSinglePageProgress toJsPayload config model =
staticData : Dict String String staticData : Dict String String
staticData = staticData =
toJsPayload.pages toJsPayload.pages
|> Dict.get (PagePath.toString page) |> Dict.get (Path.toRelative page)
|> Maybe.withDefault Dict.empty |> Maybe.withDefault Dict.empty
currentPage : { path : Path, frontmatter : route } currentPage : { path : Path, frontmatter : route }
currentPage = currentPage =
{ path = page |> PagePath.toPath |> Path.join, frontmatter = config.urlToRoute currentUrl } { path = page, frontmatter = config.urlToRoute currentUrl }
pageDataResult : Result BuildError pageData pageDataResult : Result BuildError pageData
pageDataResult = pageDataResult =
@ -1023,7 +1022,7 @@ sendSinglePageProgress toJsPayload config model =
{ protocol = Url.Https { protocol = Url.Https
, host = config.site allRoutes |> .canonicalUrl , host = config.site allRoutes |> .canonicalUrl
, port_ = Nothing , port_ = Nothing
, path = page |> PagePath.toString , path = page |> Path.toRelative
, query = Nothing , query = Nothing
, fragment = Nothing , fragment = Nothing
} }
@ -1065,10 +1064,10 @@ sendSinglePageProgress toJsPayload config model =
(config.view currentPage sharedData pageData |> .head) (config.view currentPage sharedData pageData |> .head)
++ (siteData |> (config.site allRoutes |> .head)) ++ (siteData |> (config.site allRoutes |> .head))
in in
{ route = page |> PagePath.toString { route = page |> Path.toRelative
, contentJson = , contentJson =
toJsPayload.pages toJsPayload.pages
|> Dict.get (PagePath.toString page) |> Dict.get (Path.toRelative page)
|> Maybe.withDefault Dict.empty |> Maybe.withDefault Dict.empty
, html = viewValue.body |> HtmlPrinter.htmlToString , html = viewValue.body |> HtmlPrinter.htmlToString
, errors = [] , errors = []

View File

@ -11,10 +11,10 @@ import HtmlPrinter exposing (htmlToString)
import Pages.Internal.ApplicationType as ApplicationType import Pages.Internal.ApplicationType as ApplicationType
import Pages.Internal.Platform.Mode as Mode exposing (Mode) import Pages.Internal.Platform.Mode as Mode exposing (Mode)
import Pages.Internal.Platform.ToJsPayload as ToJsPayload exposing (ToJsPayload) import Pages.Internal.Platform.ToJsPayload as ToJsPayload exposing (ToJsPayload)
import Pages.PagePath exposing (PagePath)
import Pages.SiteConfig exposing (SiteConfig) import Pages.SiteConfig exposing (SiteConfig)
import Pages.StaticHttp.Request as HashRequest import Pages.StaticHttp.Request as HashRequest
import Pages.StaticHttpRequest as StaticHttpRequest import Pages.StaticHttpRequest as StaticHttpRequest
import Path exposing (Path)
import RequestsAndPending exposing (RequestsAndPending) import RequestsAndPending exposing (RequestsAndPending)
import Secrets import Secrets
import SecretsDict exposing (SecretsDict) import SecretsDict exposing (SecretsDict)
@ -102,7 +102,7 @@ renderSingleRoute :
{ config { config
| routeToPath : route -> List String | routeToPath : route -> List String
} }
-> { path : PagePath, frontmatter : route } -> { path : Path, frontmatter : route }
-> DataSource.DataSource a -> DataSource.DataSource a
-> DataSource.DataSource b -> DataSource.DataSource b
-> StaticResponses -> StaticResponses

View File

@ -1,6 +1,6 @@
module Path exposing module Path exposing
( Path, join, fromString ( Path, join, fromString
, toAbsolute, toSegments , toAbsolute, toRelative, toSegments
) )
{-| Represents the path portion of a URL (not query parameters, fragment, protocol, port, etc.). {-| Represents the path portion of a URL (not query parameters, fragment, protocol, port, etc.).
@ -25,7 +25,7 @@ second does not.
## Turning Paths to String ## Turning Paths to String
@docs toAbsolute, toSegments @docs toAbsolute, toRelative, toSegments
-} -}
@ -72,6 +72,13 @@ toAbsolute (Path path) =
"/" ++ path "/" ++ path
{-| Turn a Path to a relative URL.
-}
toRelative : Path -> String
toRelative (Path path) =
path
normalize : String -> String normalize : String -> String
normalize pathPart = normalize pathPart =
pathPart pathPart

View File

@ -3,23 +3,20 @@ module RenderRequest exposing (..)
import ApiRoute import ApiRoute
import HtmlPrinter import HtmlPrinter
import Json.Decode as Decode import Json.Decode as Decode
import Pages.PagePath as PagePath exposing (PagePath)
import Pages.ProgramConfig exposing (ProgramConfig) import Pages.ProgramConfig exposing (ProgramConfig)
import Path exposing (Path)
import Regex import Regex
import Url exposing (Url) import Url exposing (Url)
type RequestPayload route type RequestPayload route
= Page { path : PagePath, frontmatter : route } = Page { path : Path, frontmatter : route }
| Api ( String, ApiRoute.Done ApiRoute.Response ) | Api ( String, ApiRoute.Done ApiRoute.Response )
| NotFound | NotFound
type RenderRequest route type RenderRequest route
= SinglePage IncludeHtml (RequestPayload route) Decode.Value = SinglePage IncludeHtml (RequestPayload route) Decode.Value
--ServerOrBuild
--| SharedData
--| GenerateFiles
| FullBuild | FullBuild
@ -38,10 +35,6 @@ type IncludeHtml
| OnlyJson | OnlyJson
type ServerOrBuild
= Server
decoder : decoder :
ProgramConfig userMsg userModel (Maybe route) siteData pageData sharedData ProgramConfig userMsg userModel (Maybe route) siteData pageData sharedData
-> Decode.Decoder (RenderRequest (Maybe route)) -> Decode.Decoder (RenderRequest (Maybe route))
@ -127,7 +120,7 @@ requestPayloadDecoder config =
else else
Page Page
{ frontmatter = route { frontmatter = route
, path = config.routeToPath route |> PagePath.build , path = config.routeToPath route |> Path.join
} }
Nothing -> Nothing ->