Fix bug: pass alt from getPicture to getImage (#5521)
This commit is contained in:
parent
58188e0536
commit
65d27666e1
3 changed files with 9 additions and 1 deletions
5
.changeset/eight-deers-repair.md
Normal file
5
.changeset/eight-deers-repair.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/image': minor
|
||||
---
|
||||
|
||||
Allows passing alt to getPicture
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue