-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
41 lines (34 loc) · 1.11 KB
/
.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
35
36
37
38
39
40
41
const Image = require("@11ty/eleventy-img"),
Cache = require("@11ty/eleventy-cache-assets");
async function imageShortcode(src, alt, sizes) {
let metadata = await Image(src, {
widths: [64, 128, 256, 512, 1024, 2048, null],
formats: ["svg", "avif", "webp", "jpeg"],
urlPath: "/img/",
outputDir: "./_site/img/"
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
// You bet we throw an error on missing alt in `imageAttributes` (alt="" works okay)
return Image.generateHTML(metadata, imageAttributes, {
whitespaceMode: "inline"
});
}
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy({ "src/icons": "/" });
eleventyConfig.addPassthroughCopy({ "src/css": "/css" });
eleventyConfig.addNunjucksAsyncShortcode("image", imageShortcode);
eleventyConfig.addLiquidShortcode("image", imageShortcode);
eleventyConfig.addJavaScriptFunction("image", imageShortcode);
return {
dir: {
input: "src",
includes: "_includes",
layouts: "_layouts"
}
};
};