-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pages should work correctly with redirects #152
Comments
Hey! I haven't used elm-pages in a while now, so my feedback might not that be that useful 😅 I'm not fully understanding the issue here.
Aren't the |
Here's one use case that I'm setting up right now for the elm-radio.com site. I want to have a real URL like
The way a netlify redirect works, it's not like symlinking a directory, where it will reroute any files in that directory. Instead, it treats
Will result in redirecting the HTML file, but not the |
Thanks for the detailed explanation! I thought the path of |
If you use a redirect with a 200 status (for example, Netlify redirects), the page should work correctly. That means:
content.json
file (with the StaticHttp data, etc.) from the correct URLThere are 3 different cases
blog/hello
->post/hello
)news/my-article
->archive/news/my-article
)elm-pages
currently only works in case 1. In case 2, there is an issue thatelm-pages
looks up metadata based on the path name. So if the path name has changed, it won't find it because the path it's looking for because it's looking forpost/hello
but it's stored in the code under the pathblog/hello
. This can be fixed by storing the path as part of thecontent.json
. It's case 3 that gets complicated with tags.Current issue with tags
You need to ensure that the
content.json
file with all the StaticHttp data and page-specific data is fetched from the correct URL. We currently hard code looking atcurrent/path/content.json
. But this breaks redirects. The more robust approach is to hard code the path to fetch thecontent.json
within the pre-rendered HTML. For example, you could encode doing a fetch ofarchive/news/my-article/content.json
, and pass that value in as a flag when initializing the Elm app. That URL will be accurate where the HTML page was served up with a redirect or not. So even if you view the page from the URLnews/my-article
, it will find thecontent.json
file at the correct URL (no redirects needed to make sure it finds the content.json file).This seems to be how GatsbyJS solves this problem, based on the preload tags that I see in their pre-rendered HTML. The links use absolute URLs to preload the page-data.json files.
The only way I can think of to robustly fetch
content.json
files for a page, even if the page was originally loaded from a 200-redirect HTML page, is to hardcode these absolute URLs. If we used relative URLs, this would only work in case 2, but not in case 3. Is there another way around this using base tags, or is it worth considering finding a new strategy to replace the tags approach?Possible alternative to tags
GatsbyJS decided not to use tags. Instead, they went with an approach where you can set a pathPrefix: https://www.gatsbyjs.com/docs/path-prefix/.
It seems like this could be a viable solution for
elm-pages
as well, because we can apply that path prefix in all the relevant places:ImagePath.toString
andPagePath.toString
(since we control how these are built with the code generation, we can simply add some context to include the path prefix in the generated code for these)content.json
filesThis would take some work to wire this in, but I believe we control all the relevant places where we would need to change these URLs.
One possible downside: you would need to be explicit about the prefix whenever you build the project. However, this may not be a downside because you'll need to get this right in the canonical site URL anyway.
Possible benefits: anchor links don't work as people expect when used with tags, so we've had some issues around that (#92 #93).
Looking for Feedback
This alternative to tags seems like a viable solution to me, and it seems like it allows us to make fetching content.json files more robust and compatible with redirects in HTML files. I'd love to hear what others think about this, too, feedback is welcome!
@icidasset, do you have any opinions on this? I'd be very interested to hear what you think. Happy to discuss on a call some time.
The text was updated successfully, but these errors were encountered: