mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 06:05:31 +03:00
Replace some PagePath references with new Path API.
This commit is contained in:
parent
5e8f7951d6
commit
3fc5abace9
@ -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.ToJsPayload as ToJsPayload exposing (ToJsSuccessPayload)
|
||||
import Pages.Internal.StaticHttpBody as StaticHttpBody
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Pages.ProgramConfig exposing (ProgramConfig)
|
||||
import Pages.StaticHttpRequest as StaticHttpRequest
|
||||
import Path exposing (Path)
|
||||
@ -52,8 +51,8 @@ type alias Model route =
|
||||
, allRawResponses : Dict String (Maybe String)
|
||||
, mode : Mode
|
||||
, pendingRequests : List { masked : RequestDetails, unmasked : RequestDetails }
|
||||
, unprocessedPages : List ( PagePath, route )
|
||||
, staticRoutes : Maybe (List ( PagePath, route ))
|
||||
, unprocessedPages : List ( Path, route )
|
||||
, staticRoutes : Maybe (List ( Path, route ))
|
||||
, maybeRequestJson : RenderRequest route
|
||||
}
|
||||
|
||||
@ -696,7 +695,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
|
||||
newRoutes
|
||||
|> List.map
|
||||
(\route ->
|
||||
( PagePath.build (config.routeToPath route)
|
||||
( Path.join (config.routeToPath route)
|
||||
, route
|
||||
)
|
||||
)
|
||||
@ -711,7 +710,7 @@ nextStepToEffect contentCache config model ( updatedStaticResponsesModel, nextSt
|
||||
newRoutes
|
||||
|> List.map
|
||||
(\route ->
|
||||
( PagePath.build (config.routeToPath route)
|
||||
( Path.join (config.routeToPath route)
|
||||
, route
|
||||
)
|
||||
)
|
||||
@ -870,7 +869,7 @@ sendSinglePageProgress :
|
||||
ToJsSuccessPayload
|
||||
-> ProgramConfig userMsg userModel route siteData pageData sharedData
|
||||
-> Model route
|
||||
-> ( PagePath, route )
|
||||
-> ( Path, route )
|
||||
-> Effect
|
||||
sendSinglePageProgress toJsPayload config model =
|
||||
\( page, route ) ->
|
||||
@ -932,7 +931,7 @@ sendSinglePageProgress toJsPayload config model =
|
||||
{ protocol = Url.Https
|
||||
, host = config.site allRoutes |> .canonicalUrl
|
||||
, port_ = Nothing
|
||||
, path = page |> PagePath.toString
|
||||
, path = page |> Path.toRelative
|
||||
, query = Nothing
|
||||
, fragment = Nothing
|
||||
}
|
||||
@ -940,12 +939,12 @@ sendSinglePageProgress toJsPayload config model =
|
||||
staticData : Dict String String
|
||||
staticData =
|
||||
toJsPayload.pages
|
||||
|> Dict.get (PagePath.toString page)
|
||||
|> Dict.get (Path.toRelative page)
|
||||
|> Maybe.withDefault Dict.empty
|
||||
|
||||
currentPage : { path : Path, frontmatter : route }
|
||||
currentPage =
|
||||
{ path = page |> PagePath.toPath |> Path.join, frontmatter = config.urlToRoute currentUrl }
|
||||
{ path = page, frontmatter = config.urlToRoute currentUrl }
|
||||
|
||||
pageDataResult : Result BuildError pageData
|
||||
pageDataResult =
|
||||
@ -970,10 +969,10 @@ sendSinglePageProgress toJsPayload config model =
|
||||
in
|
||||
case Result.map3 (\a b c -> ( a, b, c )) pageFoundResult renderedResult siteDataResult of
|
||||
Ok ( pageFound, rendered, siteData ) ->
|
||||
{ route = page |> PagePath.toString
|
||||
{ route = page |> Path.toRelative
|
||||
, contentJson =
|
||||
toJsPayload.pages
|
||||
|> Dict.get (PagePath.toString page)
|
||||
|> Dict.get (Path.toRelative page)
|
||||
|> Maybe.withDefault Dict.empty
|
||||
, html = rendered.view
|
||||
, errors = []
|
||||
@ -994,12 +993,12 @@ sendSinglePageProgress toJsPayload config model =
|
||||
staticData : Dict String String
|
||||
staticData =
|
||||
toJsPayload.pages
|
||||
|> Dict.get (PagePath.toString page)
|
||||
|> Dict.get (Path.toRelative page)
|
||||
|> Maybe.withDefault Dict.empty
|
||||
|
||||
currentPage : { path : Path, frontmatter : route }
|
||||
currentPage =
|
||||
{ path = page |> PagePath.toPath |> Path.join, frontmatter = config.urlToRoute currentUrl }
|
||||
{ path = page, frontmatter = config.urlToRoute currentUrl }
|
||||
|
||||
pageDataResult : Result BuildError pageData
|
||||
pageDataResult =
|
||||
@ -1023,7 +1022,7 @@ sendSinglePageProgress toJsPayload config model =
|
||||
{ protocol = Url.Https
|
||||
, host = config.site allRoutes |> .canonicalUrl
|
||||
, port_ = Nothing
|
||||
, path = page |> PagePath.toString
|
||||
, path = page |> Path.toRelative
|
||||
, query = Nothing
|
||||
, fragment = Nothing
|
||||
}
|
||||
@ -1065,10 +1064,10 @@ sendSinglePageProgress toJsPayload config model =
|
||||
(config.view currentPage sharedData pageData |> .head)
|
||||
++ (siteData |> (config.site allRoutes |> .head))
|
||||
in
|
||||
{ route = page |> PagePath.toString
|
||||
{ route = page |> Path.toRelative
|
||||
, contentJson =
|
||||
toJsPayload.pages
|
||||
|> Dict.get (PagePath.toString page)
|
||||
|> Dict.get (Path.toRelative page)
|
||||
|> Maybe.withDefault Dict.empty
|
||||
, html = viewValue.body |> HtmlPrinter.htmlToString
|
||||
, errors = []
|
||||
|
@ -11,10 +11,10 @@ import HtmlPrinter exposing (htmlToString)
|
||||
import Pages.Internal.ApplicationType as ApplicationType
|
||||
import Pages.Internal.Platform.Mode as Mode exposing (Mode)
|
||||
import Pages.Internal.Platform.ToJsPayload as ToJsPayload exposing (ToJsPayload)
|
||||
import Pages.PagePath exposing (PagePath)
|
||||
import Pages.SiteConfig exposing (SiteConfig)
|
||||
import Pages.StaticHttp.Request as HashRequest
|
||||
import Pages.StaticHttpRequest as StaticHttpRequest
|
||||
import Path exposing (Path)
|
||||
import RequestsAndPending exposing (RequestsAndPending)
|
||||
import Secrets
|
||||
import SecretsDict exposing (SecretsDict)
|
||||
@ -102,7 +102,7 @@ renderSingleRoute :
|
||||
{ config
|
||||
| routeToPath : route -> List String
|
||||
}
|
||||
-> { path : PagePath, frontmatter : route }
|
||||
-> { path : Path, frontmatter : route }
|
||||
-> DataSource.DataSource a
|
||||
-> DataSource.DataSource b
|
||||
-> StaticResponses
|
||||
|
11
src/Path.elm
11
src/Path.elm
@ -1,6 +1,6 @@
|
||||
module Path exposing
|
||||
( Path, join, fromString
|
||||
, toAbsolute, toSegments
|
||||
, toAbsolute, toRelative, toSegments
|
||||
)
|
||||
|
||||
{-| 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
|
||||
|
||||
@docs toAbsolute, toSegments
|
||||
@docs toAbsolute, toRelative, toSegments
|
||||
|
||||
-}
|
||||
|
||||
@ -72,6 +72,13 @@ toAbsolute (Path path) =
|
||||
"/" ++ path
|
||||
|
||||
|
||||
{-| Turn a Path to a relative URL.
|
||||
-}
|
||||
toRelative : Path -> String
|
||||
toRelative (Path path) =
|
||||
path
|
||||
|
||||
|
||||
normalize : String -> String
|
||||
normalize pathPart =
|
||||
pathPart
|
||||
|
@ -3,23 +3,20 @@ module RenderRequest exposing (..)
|
||||
import ApiRoute
|
||||
import HtmlPrinter
|
||||
import Json.Decode as Decode
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Pages.ProgramConfig exposing (ProgramConfig)
|
||||
import Path exposing (Path)
|
||||
import Regex
|
||||
import Url exposing (Url)
|
||||
|
||||
|
||||
type RequestPayload route
|
||||
= Page { path : PagePath, frontmatter : route }
|
||||
= Page { path : Path, frontmatter : route }
|
||||
| Api ( String, ApiRoute.Done ApiRoute.Response )
|
||||
| NotFound
|
||||
|
||||
|
||||
type RenderRequest route
|
||||
= SinglePage IncludeHtml (RequestPayload route) Decode.Value
|
||||
--ServerOrBuild
|
||||
--| SharedData
|
||||
--| GenerateFiles
|
||||
| FullBuild
|
||||
|
||||
|
||||
@ -38,10 +35,6 @@ type IncludeHtml
|
||||
| OnlyJson
|
||||
|
||||
|
||||
type ServerOrBuild
|
||||
= Server
|
||||
|
||||
|
||||
decoder :
|
||||
ProgramConfig userMsg userModel (Maybe route) siteData pageData sharedData
|
||||
-> Decode.Decoder (RenderRequest (Maybe route))
|
||||
@ -127,7 +120,7 @@ requestPayloadDecoder config =
|
||||
else
|
||||
Page
|
||||
{ frontmatter = route
|
||||
, path = config.routeToPath route |> PagePath.build
|
||||
, path = config.routeToPath route |> Path.join
|
||||
}
|
||||
|
||||
Nothing ->
|
||||
|
Loading…
Reference in New Issue
Block a user