Skip to content

Commit

Permalink
Ignore /vercel/image images + better message on _jampack
Browse files Browse the repository at this point in the history
  • Loading branch information
georges-gomes committed May 24, 2024
1 parent f36f481 commit 116ec40
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@divriots/jampack",
"version": "0.24.3",
"version": "0.24.4",
"cache-version": {
"img": "v1",
"img-ext": "v1"
Expand Down
2 changes: 2 additions & 0 deletions src/config-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const default_options: Options = {
srcset_min_width: 390 * 2, // HiDPI phone
srcset_max_width: 1920 * 2, // 4K
max_width: 99999,
src_include: /^.*$/,
src_exclude: /^\/vercel\/image\?/, // Ignore /vervel/image? URLs because not local and most likely already optimized,
external: {
process: 'off',
src_include: /^.*$/,
Expand Down
2 changes: 2 additions & 0 deletions src/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export type Options = {
srcset_min_width: number; // Minimum width of generate image in srcset
srcset_max_width: number; // Maximum width of generate image in srcset
max_width: number; // Maximum width of original images - if bigger => resized output
src_include: RegExp;
src_exclude: RegExp | null;
external: {
process:
| 'off' // Default
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ program
try {
mkdirSync(join(dir, '_jampack'));
} catch (e) {
console.error('Failed to create `_jampack` folder.');
console.error(
'Folder `_jampack` is present in target folder. This means that jampack has already processed this folder. You should always run jampack on clean build of the static website.'
);
exit(1);
}

Expand Down
8 changes: 8 additions & 0 deletions src/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ async function processImage(
* Attribute 'src'
*/
let attrib_src = img.attr('src');

if (!attrib_src) {
const attrib_data_src = img.attr('data-src');
if (attrib_data_src) {
Expand All @@ -276,6 +277,13 @@ async function processImage(
return;
}

if (
!isIncluded(attrib_src, config.image.src_include, config.image.src_exclude)
) {
// Setup to ignore
return;
}

/*
* Attribute 'alt'
*/
Expand Down

0 comments on commit 116ec40

Please sign in to comment.