forked from 11ty/eleventy-img
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds in memory cache to avoid repeated work (keyed to input file size…
… for now). Adds dryRun and useCache options.
- Loading branch information
Showing
5 changed files
with
172 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const fs = require("fs"); | ||
|
||
class FileSizeCache { | ||
constructor() { | ||
this.cache = {}; | ||
} | ||
|
||
getSize(path) { | ||
let stats = fs.statSync(path); | ||
return stats.size; | ||
} | ||
|
||
add(options, results) { | ||
let key = JSON.stringify(options); | ||
|
||
this.cache[key] = { | ||
results | ||
}; | ||
} | ||
|
||
get(options) { | ||
let key = JSON.stringify(options); | ||
if(this.cache[key]) { | ||
// may return promise | ||
return this.cache[key].results; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
module.exports = FileSizeCache; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,30 @@ | ||
const eleventyImage = require("../"); | ||
|
||
(async () => { | ||
// Twitter removed this URL | ||
// await eleventyImage(`https://twitter.com/zachleat/profile_image?size=bigger`) | ||
// await eleventyImage(`https://twitter.com/eleven_ty/profile_image?size=bigger`, { | ||
// widths: [48] | ||
// }); | ||
|
||
// await eleventyImage(`https://unavatar.now.sh/twitter/zachleat?fallback=false`, { | ||
// widths: [75, null], | ||
// formats: [null] | ||
// }); | ||
|
||
// await eleventyImage(`https://unavatar.now.sh/twitter/zachleat?fallback=false`, { | ||
// widths: [null], | ||
// formats: ["svg"], | ||
// }); | ||
|
||
// upscale svg issue #32 | ||
console.log( await eleventyImage(`https://www.netlify.com/v3/img/components/leaves.svg`, { | ||
let leaves1 = await eleventyImage(`https://www.netlify.com/v3/img/components/leaves.svg`, { | ||
formats: ["png", "avif"], | ||
widths: [2000], | ||
svgShortCircuit: true, | ||
})); | ||
}); | ||
console.log( { leaves1 } ); | ||
|
||
let leaves = await eleventyImage(`https://www.netlify.com/v3/img/components/leaves.svg`, { | ||
let leaves2 = await eleventyImage(`https://www.netlify.com/v3/img/components/leaves.svg`, { | ||
formats: ["svg", "webp", "jpeg", "png"], | ||
// formats: [null], | ||
widths: [400, 800, null], | ||
svgShortCircuit: true, | ||
}); | ||
console.log( leaves ); | ||
console.log( { leaves2 } ); | ||
|
||
let mexicoFlag = await eleventyImage("../test/Flag_of_Mexico.svg", { | ||
formats: ["svg", "avif"], | ||
widths: [600, null], | ||
}); | ||
console.log( mexicoFlag ); | ||
console.log( { mexicoFlag } ); | ||
|
||
// let results = await eleventyImage("../test/bio-2017.jpg", { | ||
// formats: ["avif", "jpeg"], | ||
// widths: [400, 1280], | ||
// }); | ||
let bioImage = await eleventyImage("../test/bio-2017.jpg", { | ||
formats: ["avif", "jpeg"], | ||
widths: [400, 1280], | ||
}); | ||
|
||
// console.log( results ); | ||
console.log( bioImage ); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters