-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleventy.config.js
49 lines (41 loc) · 1.56 KB
/
eleventy.config.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
42
43
44
45
46
47
48
49
const filters = require('./_11ty/filters.js');
const path = require("path");
const eleventyImage = require("@11ty/eleventy-img");
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy('src/images');
eleventyConfig.addPassthroughCopy('src/css');
eleventyConfig.addPassthroughCopy('src/js');
eleventyConfig.addPassthroughCopy('src/videos');
eleventyConfig.addPassthroughCopy('projects/images');
eleventyConfig.addShortcode("bodyClass", function (pageUrl) {
return pageUrl === "/" ? "home" : "subpage";
});
// Filters
Object.keys(filters).forEach(filterName => {
eleventyConfig.addFilter(filterName, filters[filterName])
});
function relativeToInputPath(inputPath, relativeFilePath) {
let split = inputPath.split("/");
split.pop();
return path.resolve(split.join(path.sep), relativeFilePath);
}
eleventyConfig.addAsyncShortcode("image", async function imageShortcode(src, alt, widths, sizes) {
let formats = ["avif", "webp", "auto"];
let file = relativeToInputPath(this.page.inputPath, src);
let metadata = await eleventyImage(file, {
widths: widths || ["auto"],
formats,
outputDir: path.join(eleventyConfig.dir.output, "img"),
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
return eleventyImage.generateHTML(metadata, imageAttributes);
});
return {
passthroughFileCopy: true
}
}