From f92910ee0c2d454a54e169796d07e209f51f375f Mon Sep 17 00:00:00 2001 From: Georges Gomes Date: Wed, 11 Sep 2024 16:16:04 +0200 Subject: [PATCH] srcset step is configurable --- src/config-default.ts | 1 + src/config-types.ts | 1 + src/optimize.ts | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/config-default.ts b/src/config-default.ts index 4db7481..8f2e253 100644 --- a/src/config-default.ts +++ b/src/config-default.ts @@ -18,6 +18,7 @@ const default_options: Options = { embed_size: 1500, srcset_min_width: 390 * 2, // HiDPI phone srcset_max_width: 1920 * 2, // 4K + srcset_step: 300, max_width: 99999, src_include: /^.*$/, src_exclude: /^\/vercel\/image\?/, // Ignore /vervel/image? URLs because not local and most likely already optimized, diff --git a/src/config-types.ts b/src/config-types.ts index db87b6a..dc8fac0 100644 --- a/src/config-types.ts +++ b/src/config-types.ts @@ -31,6 +31,7 @@ export type Options = { embed_size: number; // Embed above the fold images if size < embed_size srcset_min_width: number; // Minimum width of generate image in srcset srcset_max_width: number; // Maximum width of generate image in srcset + srcset_step: number; // Number of pixels between sizes in srcset max_width: number; // Maximum width of original images - if bigger => resized output src_include: RegExp; src_exclude: RegExp | null; diff --git a/src/optimize.ts b/src/optimize.ts index fddecc4..8d423cb 100755 --- a/src/optimize.ts +++ b/src/optimize.ts @@ -737,7 +737,7 @@ async function _generateSrcSet( } // Start reduction - const step = 300; //px + const step = options.image.srcset_step; //px let valueW = !startSrc ? imageWidth : imageWidth - step; valueW = Math.min(valueW, options.image.srcset_max_width);