Fix missing content flash for paths that weren't normalized correctly.

This commit is contained in:
Dillon Kearns 2020-01-22 20:57:19 -08:00
parent 4ea2e47e98
commit 5b12ab452d
2 changed files with 29 additions and 1 deletions

View File

@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Fixed
- Fix missing content flash (that was partially fixed with [#48](https://github.com/dillonkearns/elm-pages/pull/48)) for
some cases where paths weren't normalized correctly.
## [1.1.8] - 2020-01-20
### Fixed

View File

@ -175,7 +175,7 @@ parseMetadata maybeInitialPageContent document content =
in
case maybeInitialPageContent of
Just { contentJson, initialUrl } ->
if initialUrl.path == ("/" ++ String.join "/" path) then
if normalizePath initialUrl.path == (String.join "/" path |> normalizePath) then
Parsed metadata
{ body = renderer contentJson.body
, staticData = contentJson.staticData
@ -195,6 +195,30 @@ parseMetadata maybeInitialPageContent document content =
)
normalizePath : String -> String
normalizePath pathString =
let
hasPrefix =
String.startsWith "/" pathString
hasSuffix =
String.endsWith "/" pathString
in
String.concat
[ if hasPrefix then
""
else
"/"
, pathString
, if hasSuffix then
""
else
"/"
]
parseContent :
String
-> String