Skip to content
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

Add support for static resources with fragments. Closes #5507 #5510

Conversation

phoebe100
Copy link
Contributor

@phoebe100 phoebe100 commented Jul 7, 2023

With this PR, you can use the ~p sigil to resolve static assets with fragment identifiers (e.g. useful to address only a specific section of an SVG image).
For instance, if you have a "digest" version of an asset:
Before:

~p"/images/icons.svg" == "/images/icons-6051db34009ab48e6232cf685fca2bd4.svg?vsn=d"
~p"/images/icons.svg#warning" == "/images/icons.svg#warning"

Now:

~p"/images/icons.svg" == "/images/icons-6051db34009ab48e6232cf685fca2bd4.svg?vsn=d"
~p"/images/icons.svg#warning" == "/images/icons-6051db34009ab48e6232cf685fca2bd4.svg?vsn=d#warning"

Closes #5507


defp path_and_fragment(path_incl_fragment) do
path_incl_fragment
|> String.split("#")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An SVG can contain a number sign in it's id, for example ~p"/images/icons.svg#warning#small".

Suggested change
|> String.split("#")
|> String.split("#", parts: 2)

@phoebe100 phoebe100 force-pushed the 5507_support_static_resource_with_fragment branch 2 times, most recently from d490a08 to 7a9ffff Compare July 11, 2023 17:21
@phoebe100 phoebe100 force-pushed the 5507_support_static_resource_with_fragment branch from 7a9ffff to a4fad82 Compare July 27, 2023 13:02
@chrismccord chrismccord merged commit 21f0041 into phoenixframework:main Aug 2, 2023
2 of 4 checks passed
@chrismccord
Copy link
Member

Thank you so much! ❤️❤️❤️🐥🔥

@phoebe100 phoebe100 deleted the 5507_support_static_resource_with_fragment branch August 2, 2023 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File with digest is not used on VerifiedRoute with anchor
3 participants