From 65d27666e1a0e668d02f7106e89f6d7b45f5de02 Mon Sep 17 00:00:00 2001 From: truesri <113232453+truesri@users.noreply.github.com> Date: Tue, 6 Dec 2022 09:17:08 +0000 Subject: [PATCH] Fix bug: pass alt from getPicture to getImage (#5521) --- .changeset/eight-deers-repair.md | 5 +++++ packages/integrations/image/src/lib/get-image.ts | 1 + packages/integrations/image/src/lib/get-picture.ts | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/eight-deers-repair.md diff --git a/.changeset/eight-deers-repair.md b/.changeset/eight-deers-repair.md new file mode 100644 index 000000000..653f4080a --- /dev/null +++ b/.changeset/eight-deers-repair.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': minor +--- + +Allows passing alt to getPicture diff --git a/packages/integrations/image/src/lib/get-image.ts b/packages/integrations/image/src/lib/get-image.ts index 3e32e6f3e..65526f653 100644 --- a/packages/integrations/image/src/lib/get-image.ts +++ b/packages/integrations/image/src/lib/get-image.ts @@ -11,6 +11,7 @@ import type { ImageMetadata } from '../vite-plugin-astro-image.js'; export interface GetImageTransform extends Omit { src: string | ImageMetadata | Promise<{ default: ImageMetadata }>; + alt: string; } function resolveSize(transform: TransformOptions): TransformOptions { diff --git a/packages/integrations/image/src/lib/get-picture.ts b/packages/integrations/image/src/lib/get-picture.ts index d4deebb79..37fea6de4 100644 --- a/packages/integrations/image/src/lib/get-picture.ts +++ b/packages/integrations/image/src/lib/get-picture.ts @@ -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']; @@ -43,7 +44,7 @@ async function resolveFormats({ src, formats }: GetPictureParams) { } export async function getPicture(params: GetPictureParams): Promise { - 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'); @@ -71,6 +72,7 @@ export async function getPicture(params: GetPictureParams): Promise { const img = await getImage({ src, + alt, format, width, fit,