Skip to content

Commit

Permalink
Fixes #64
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Feb 14, 2021
1 parent 31975ef commit c152641
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions img.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const MIME_TYPES = {
"avif": "image/avif",
};

const FORMAT_ALIASES = {
"jpg": "jpeg"
};

/* Size Cache */
let sizeCache = new FileSizeCache();

Expand All @@ -76,6 +80,13 @@ function getFormatsArray(formats) {
formats = formats.split(",");
}

formats = formats.map(format => {
if(FORMAT_ALIASES[format]) {
return FORMAT_ALIASES[format];
}
return format;
});

// svg must come first for possible short circuiting
formats.sort((a, b) => {
if(a === "svg") {
Expand Down
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,26 @@ test("Test with a string float width", async t => {

t.deepEqual(image.jpeg[0].width, 340);
});

test("Using `jpg` in formats Issue #64", async t => {
let stats = await eleventyImage("./test/bio-2017.jpg", {
formats: ["jpg"],
dryRun: true,
});
delete stats.jpeg[0].buffer;
t.deepEqual(stats, {
jpeg: [
{
filename: '97854483-1280.jpeg',
format: 'jpeg',
height: 853,
outputPath: 'img/97854483-1280.jpeg',
size: 276231,
sourceType: "image/jpeg",
srcset: '/img/97854483-1280.jpeg 1280w',
url: '/img/97854483-1280.jpeg',
width: 1280,
},
]
});
});

0 comments on commit c152641

Please sign in to comment.