Skip to content

Commit

Permalink
srcset step is configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
georges-gomes committed Sep 11, 2024
1 parent 4768fb9 commit f92910e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit f92910e

Please sign in to comment.