Skip to content

Commit

Permalink
Fix bug: pass alt from getPicture to getImage
Browse files Browse the repository at this point in the history
  • Loading branch information
truesri committed Dec 3, 2022
1 parent a1885ea commit e9229ed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
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

0 comments on commit e9229ed

Please sign in to comment.