-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
63 lines (52 loc) · 1.56 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
63
const Image = require("@11ty/eleventy-img")
const htmlmin = require('html-minifier')
const now = String(Date.now())
async function imageShortcode(src, alt, sizes = "100vw") {
let metadata = await Image(`${src}`, {
widths: [600, 1000, 1600],
formats: ["avif", "jpeg"],
urlPath: "/img/",
outputDir: "./_site/img/"
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
return Image.generateHTML(metadata, imageAttributes);
}
module.exports = function (eleventyConfig) {
eleventyConfig.addNunjucksAsyncShortcode("image", imageShortcode)
eleventyConfig.setUseGitIgnore(false)
eleventyConfig.addPassthroughCopy("images")
eleventyConfig.addPassthroughCopy("favicon.png")
eleventyConfig.addPassthroughCopy("fonts")
eleventyConfig.addPassthroughCopy("site.webmanifest")
eleventyConfig.addWatchTarget('./_tmp/style.css')
eleventyConfig.addPassthroughCopy({ './_tmp/style.css': './style.css' })
eleventyConfig.addPassthroughCopy({
'./node_modules/alpinejs/dist/alpine.js': './js/alpine.js',
})
eleventyConfig.addShortcode('version', function () {
return now
})
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
if (
process.env.ELEVENTY_PRODUCTION &&
outputPath &&
outputPath.endsWith('.html')
) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified
}
return content
});
return {
htmlTemplateEngine: "njk",
};
}