-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
34 lines (29 loc) · 836 Bytes
/
.eleventy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const Image = require("@11ty/eleventy-img");
async function imageShortcode(src, alt, sizes) {
let metadata = await Image(src, {
widths: [300, 600, 900, 1200, 1500],
formats: ["avif", "webp", "jpeg", null],
outputDir: "_site/image/optimized/",
urlPath: "/image/optimized/",
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
return Image.generateHTML(metadata, imageAttributes, {
whitespaceMode: "inline",
});
}
module.exports = function (eleventyConfig) {
// Route overides
eleventyConfig.addPassthroughCopy({ "client/assets": "/" }, () => {
return {
passthroughFileCopy: true,
};
});
// Image optmizer
eleventyConfig.addLiquidShortcode("image", imageShortcode);
eleventyConfig.addJavaScriptFunction("image", imageShortcode);
};