-
Notifications
You must be signed in to change notification settings - Fork 71
feat: add option to customise URL parsing in IPX server #259
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #259 +/- ##
==========================================
- Coverage 56.02% 48.55% -7.48%
==========================================
Files 14 13 -1
Lines 1203 898 -305
Branches 83 91 +8
==========================================
- Hits 674 436 -238
+ Misses 526 459 -67
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This is a nice idea! We probably need to introduce it for the next major version, as new behavior can still potentially conflict with valid file names. Also what do you think to use |
I will also think more about whole implementation part, we might make URL parser configurable to avoid need of |
I agree, making it configurable would be nice. 🤔 We could provide parsers for the old and new style, and allow the user to create their own. How would you feel about this schema? export type IPXOptions = {
urlPathParser?: 'modifiers-in-path' | 'modifiers-in-filename'
| ((path: string) => { modifiers: Record<string, string>; id: string; })
// ...
}
There is an established convention of naming image files like |
Regarding the change in SVG logic (comment has disappeared?)... One caveat with the new URL style is that it requires the target format to be specified. It wouldn't be right to request The previous logic allowed SVG files to be returned as-is (or optimised with SVGO) when the target format was omitted:
But it didn't allow
I revised the logic so that Which permits the following to work:
|
Thanks for explanations. Can you update PR to only add support for urlPathParser (i would call it simply parseURL)? (no change in svg part we can do in another PR and also not named presets, only if not set, we have default parser for current behavior) |
This reverts commit bc91fe9.
@pi0 I have revised this PR to just add the |
@pi0 I just realised this PR was still in draft mode. It is ready for review when you can |
This PR enables customisation of IPX image URLs.
When creating an H3 handler,
parseUrl
option can be set to a function which overrides the default URL parsing logic.When not set, the default logic will be used, which accepts URLs in the form
/<modifiers>/<id>
.As an example, below is a
parseUrl
function for an alternative URL style in the form/<id>@@<modifiers>.<format>
— this puts the modifiers in the filename after an@@
sequence, and the format as the file extension. Such an URL style could be preferable when using IPX to prerender images for static hosting.Resolves #54, #160