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 validateOptions hook to Image Service API #6555

Merged
merged 3 commits into from
Mar 17, 2023

Conversation

Princesseuh
Copy link
Member

@Princesseuh Princesseuh commented Mar 15, 2023

Changes

Add a validateOption hook that can be used to validate / augment the passed options by the user. This is necessary because certain options (namely format) need to be augmented before reaching other hooks / addStaticImage.

For instance, for format, if we change the file format inside transform like we did previously, the final file will have the wrong file extension because the path has already been decided before transform. And while it's possible to correct the output path (since transform returns the outputted format), then we would have the wrong file path in the HTML file as it would point to the previous file extension. This hook solves that. I tried to find another solution, but this was the easiest one.

Fun-fact: This hook was present in the first version of the RFC, but it was removed during internal discussions as I could not remember the use case, oops.

Fix #6540

Testing

Added a test testing the fix, which uses the hook

Docs

withastro/docs#2859

@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2023

🦋 Changeset detected

Latest commit: 6f1d337

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) feat: markdown Related to Markdown (scope) labels Mar 15, 2023
@Princesseuh Princesseuh changed the title [WIP] Add validateOptions hook to Image Service API Add validateOptions hook to Image Service API Mar 15, 2023
@Princesseuh Princesseuh marked this pull request as ready for review March 15, 2023 13:25
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Nice! I like how all the validations are in one spot now.

@Princesseuh Princesseuh merged commit f5fddaf into main Mar 17, 2023
@Princesseuh Princesseuh deleted the feat/image-validate-options branch March 17, 2023 12:29
@astrobot-houston astrobot-houston mentioned this pull request Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: markdown Related to Markdown (scope) pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[assets] Optimized image uses original file extension
2 participants