mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-23 22:26:16 +03:00
Use a plain List String
for Path instead of Custom Type.
This commit is contained in:
parent
ecf2dc897c
commit
74249406f9
@ -148,7 +148,7 @@ linkInner currentPagePath linkTo name =
|
||||
let
|
||||
isCurrentPath : Bool
|
||||
isCurrentPath =
|
||||
List.head (Path.toSegments currentPagePath) == Just linkTo
|
||||
List.head currentPagePath == Just linkTo
|
||||
in
|
||||
span
|
||||
[ css
|
||||
|
@ -452,7 +452,7 @@ view shared model app =
|
||||
optimisticVisibility =
|
||||
case app.transition of
|
||||
Just (Pages.Transition.Loading path _) ->
|
||||
case path |> Path.toSegments of
|
||||
case path of
|
||||
[ "active" ] ->
|
||||
Active
|
||||
|
||||
|
35
src/Path.elm
35
src/Path.elm
@ -40,20 +40,25 @@ import Pages.Internal.String exposing (chopEnd, chopStart)
|
||||
|
||||
{-| The path portion of the URL, normalized to ensure that path segments are joined with `/`s in the right places (no doubled up or missing slashes).
|
||||
-}
|
||||
type Path
|
||||
= Path String
|
||||
type alias Path =
|
||||
List String
|
||||
|
||||
|
||||
{-| Create a Path from multiple path parts. Each part can either be a single path segment, like `blog`, or a
|
||||
multi-part path part, like `blog/post-1`.
|
||||
{-| Turn a Path to a relative URL.
|
||||
-}
|
||||
join : List String -> Path
|
||||
join : Path -> Path
|
||||
join parts =
|
||||
parts
|
||||
|> List.filter (\segment -> segment /= "/")
|
||||
|> List.map normalize
|
||||
|
||||
|
||||
{-| Turn a Path to a relative URL.
|
||||
-}
|
||||
toRelative : Path -> String
|
||||
toRelative parts =
|
||||
join parts
|
||||
|> String.join "/"
|
||||
|> Path
|
||||
|
||||
|
||||
{-| Create a Path from a path String.
|
||||
@ -66,28 +71,20 @@ join parts =
|
||||
fromString : String -> Path
|
||||
fromString path =
|
||||
path
|
||||
|> normalize
|
||||
|> Path
|
||||
|> toSegments
|
||||
|
||||
|
||||
{-| -}
|
||||
toSegments : Path -> List String
|
||||
toSegments (Path path) =
|
||||
toSegments : String -> List String
|
||||
toSegments path =
|
||||
path |> String.split "/" |> List.filter ((/=) "")
|
||||
|
||||
|
||||
{-| Turn a Path to an absolute URL (with no trailing slash).
|
||||
-}
|
||||
toAbsolute : Path -> String
|
||||
toAbsolute (Path path) =
|
||||
"/" ++ path
|
||||
|
||||
|
||||
{-| Turn a Path to a relative URL.
|
||||
-}
|
||||
toRelative : Path -> String
|
||||
toRelative (Path path) =
|
||||
path
|
||||
toAbsolute path =
|
||||
"/" ++ toRelative path
|
||||
|
||||
|
||||
normalize : String -> String
|
||||
|
Loading…
Reference in New Issue
Block a user