Skip to content

Commit c12089a

Browse files
committed
remove 'fit', 'w', & 'h' on gifs
1 parent dbb9b85 commit c12089a

File tree

4 files changed

+473
-1727
lines changed

4 files changed

+473
-1727
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"extends": ["@delicious-simplicity/eslint-config"]
2+
"extends": ["@delicious-simplicity/eslint-config"],
3+
"ignorePatterns": ["cjs/*", "dist/*", "esm/*", "types/*"]
34
}

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@delicious-simplicity/next-image-contentful-loader",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"repository": "https://github.com/delicious-simplicity/next-image-contentful-loader.git",
55
"author": "Devin Metivier <devinmetivier@gmail.com>",
66
"contributors": [
@@ -34,9 +34,10 @@
3434
"lint:fix": "eslint . --ext .js,.ts,.jsx,.tsx --fix"
3535
},
3636
"devDependencies": {
37-
"@delicious-simplicity/eslint-config": "^1.0.1",
38-
"@vercel/ncc": "^0.31.1",
39-
"next": "^12.0.3",
40-
"typescript": "^4.4.4"
37+
"@delicious-simplicity/eslint-config": "^1.0.3",
38+
"@types/node": "^17.0.23",
39+
"@vercel/ncc": "^0.33.4",
40+
"next": "^12.1.4",
41+
"typescript": "^4.6.3"
4142
}
4243
}

src/nextContentfulLoader.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { parseAspectRatio } from './parseAspectRatio';
44

55
export type ContentfulImageParams = {
66
ar?: string;
7-
87
fm?: 'jpg' | 'png' | 'webp' | 'gif' | 'avif';
98
fl?: 'progressive' | 'png8';
109
w?: number;
@@ -69,5 +68,12 @@ export const contentfulLoader = (loaderProps: ImageLoaderProps, contentfulParams
6968
delete adjustedContentfulParams['ar'];
7069
if (typeof adjustedContentfulParams['h'] === 'undefined') delete adjustedContentfulParams['h'];
7170

71+
// remove width and height if requesting a gif
72+
if (/\.gif$/gim.test(loaderProps.src)) {
73+
delete adjustedContentfulParams['w'];
74+
delete adjustedContentfulParams['h'];
75+
delete adjustedContentfulParams['fit'];
76+
}
77+
7278
return `${loaderProps.src}?${new URLSearchParams(adjustedContentfulParams as { [key: string]: string }).toString()}`;
7379
};

0 commit comments

Comments
 (0)