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

Fix bug: pass alt from getPicture to getImage #5521

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-deers-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/image': minor
---

Allows passing alt to getPicture
1 change: 1 addition & 0 deletions packages/integrations/image/src/lib/get-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { ImageMetadata } from '../vite-plugin-astro-image.js';

export interface GetImageTransform extends Omit<TransformOptions, 'src'> {
src: string | ImageMetadata | Promise<{ default: ImageMetadata }>;
alt: string;
}

function resolveSize(transform: TransformOptions): TransformOptions {
Expand Down
4 changes: 3 additions & 1 deletion packages/integrations/image/src/lib/get-picture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getImage } from './get-image.js';

export interface GetPictureParams {
src: string | ImageMetadata | Promise<{ default: ImageMetadata }>;
alt: string;
widths: number[];
formats: OutputFormat[];
aspectRatio?: TransformOptions['aspectRatio'];
Expand Down Expand Up @@ -43,7 +44,7 @@ async function resolveFormats({ src, formats }: GetPictureParams) {
}

export async function getPicture(params: GetPictureParams): Promise<GetPictureResult> {
const { src, widths, fit, position, background } = params;
const { src, alt, widths, fit, position, background } = params;

if (!src) {
throw new Error('[@astrojs/image] `src` is required');
Expand Down Expand Up @@ -71,6 +72,7 @@ export async function getPicture(params: GetPictureParams): Promise<GetPictureRe
widths.map(async (width) => {
const img = await getImage({
src,
alt,
format,
width,
fit,
Expand Down