-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
62 lines (53 loc) · 1.75 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// --- START, eleventy-img ---
const Image = require("@11ty/eleventy-img");
const path = require("path");
async function imageShortcode(src, alt, sizes) {
let metadata = await Image(src, {
widths: [300, 600, 1400],
formats: ["webp", "jpeg"],
outputDir: "_site/img",
filenameFormat: function (id, src, width, format) {
const extension = path.extname(src);
const name = path.basename(src, extension);
return `${name}-${width}w.${format}`;
},
});
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);
}
// --- END, eleventy-img ---
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("js");
eleventyConfig.addPassthroughCopy("robots.txt");
// Shortcode to place confetti only on formsuccess page
eleventyConfig.addShortcode("formSuccessConfetti", function (value) {
if (value === "form-success") {
return `<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script><script src="/js/confetti.js"></script>`;
}
});
// Shortcode for eleventy-img plugin
eleventyConfig.addNunjucksAsyncShortcode("image", imageShortcode);
// Shortcode for the current year
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
eleventyConfig.addFilter("debugger", (...args) => {
console.log(...args);
debugger;
});
return {
markdownTemplateEngine: "njk",
dataTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dir: {
input: "src",
output: "_site",
includes: "_includes",
data: "_data",
},
};
};