diff --git a/src/components/picture.tsx b/src/components/picture.tsx index acb4f82..3db9858 100644 --- a/src/components/picture.tsx +++ b/src/components/picture.tsx @@ -17,6 +17,7 @@ export interface State { interface SrcSetInfo { jpeg: string; webp: string; + avif: string; bestSrc: string; } @@ -45,6 +46,10 @@ export class Picture extends React.PureComponent { return ( + { srcSet.avif !== "" + ? + : null + } { private _srcset = (): SrcSetInfo => { const jpegSrcSet: string[] = []; const webpSrcSet: string[] = []; + const avifSrcSet: string[] = []; let bestSize = 800; let bestScale = Infinity; @@ -75,8 +81,12 @@ export class Picture extends React.PureComponent { if (scale >= 1 || size === 2400) { const jpeg = `img/${size}/${this.props.image.src}`; const webp = jpeg.replace("jpg", "webp"); + const avif = jpeg.replace("jpg", "avif"); jpegSrcSet.push(`${jpeg} ${scale}x`); webpSrcSet.push(`${webp} ${scale}x`); + if (this.props.image.hdr) { + avifSrcSet.push(`${avif} ${scale}x`); + } if (scale < bestScale) { bestSize = size; bestScale = scale; @@ -87,6 +97,7 @@ export class Picture extends React.PureComponent { return { jpeg: jpegSrcSet.join(","), webp: webpSrcSet.join(","), + avif: avifSrcSet.join(","), bestSrc: `img/${bestSize}/${this.props.image.src}`, }; }; diff --git a/src/model.ts b/src/model.ts index 566b1a4..6b2d3a7 100644 --- a/src/model.ts +++ b/src/model.ts @@ -16,4 +16,5 @@ export interface Image { src: string; height: number; width: number; + hdr?: boolean; }