diff --git a/src/components/picture.tsx b/src/components/picture.tsx index 4aa4741..d8555a8 100644 --- a/src/components/picture.tsx +++ b/src/components/picture.tsx @@ -14,7 +14,8 @@ export interface State { } interface SrcSetInfo { - srcSet: string; + jpeg: string; + webp: string; bestSrc: string; } @@ -44,17 +45,21 @@ export class Picture extends React.PureComponent { const srcSet = this._srcset(); return ( - + + + + + ); } private _srcset = (): SrcSetInfo => { - const srcs: string[] = []; + const jpegSrcSet: string[] = []; + const webpSrcSet: string[] = []; let bestSize = 1600; let bestRatio = Infinity; @@ -67,7 +72,10 @@ export class Picture extends React.PureComponent { const scale = width / this.props.width; if (scale >= 1) { - srcs.push(`img/${size}/${this.props.image.src} ${scale}x`); + const jpeg = `img/${size}/${this.props.image.src}`; + const webp = jpeg.replace("jpg", "webp"); + jpegSrcSet.push(`${jpeg} ${scale}x`); + webpSrcSet.push(`${webp} ${scale}x`); if (scale < bestRatio) { bestSize = size; bestRatio = scale; @@ -75,10 +83,9 @@ export class Picture extends React.PureComponent { } }); - srcs.push(`img/${bestSize}/${this.props.image.src} 1x`); - return { - srcSet: srcs.join(","), + jpeg: jpegSrcSet.join(","), + webp: webpSrcSet.join(","), bestSrc: `img/${bestSize}/${this.props.image.src}` }; }; diff --git a/src/model.ts b/src/model.ts index 0770f9b..2e45844 100644 --- a/src/model.ts +++ b/src/model.ts @@ -1,9 +1,9 @@ export const SIZES = [1600, 1200, 800, 600, 400, 200]; export function dataUrl() { - return (window.location.host === "ski.aarongutierrez.com") - ? "https://s3-us-west-2.amazonaws.com/ski.aarongutierrez.com/img/data.json" - : "img/data.json"; + return window.location.host === "ski.aarongutierrez.com" + ? "https://s3-us-west-2.amazonaws.com/ski.aarongutierrez.com/img/data.json" + : "img/data.json"; } export interface Data {