Fix bug: pass alt from getPicture to getImage (#5521)

This commit is contained in:
truesri 2022-12-06 09:17:08 +00:00 committed by GitHub
parent 58188e0536
commit 65d27666e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/image': minor
---
Allows passing alt to getPicture

View file

@ -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 {

View file

@ -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<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');
@ -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,