-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.js
87 lines (74 loc) · 2.11 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import "dotenv/config";
import htmlmin from "html-minifier-terser";
import readableDate from './src/lib/filters/readableDate.js';
import path from "path";
import { eleventyImageTransformPlugin } from '@11ty/eleventy-img';
import Image from "@11ty/eleventy-img";
export default function(eleventyConfig) {
const isProd = process.env.NODE_ENV === "production";
// Ssst!
eleventyConfig.setQuietMode(true);
// Watch
eleventyConfig.addWatchTarget('src/js/');
eleventyConfig.addWatchTarget('src/css/');
// Pass-through
eleventyConfig.addPassthroughCopy({
"src/assets/": "/assets/",
"src/media/processed/" : "/media/processed",
"src/css/tw/tw.build.css" : "/css/tw.css",
});
// Filters
eleventyConfig.addFilter('readableDate', readableDate);
// Images
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
extensions: "html",
formats: ["webp", "jpeg"],
// formats: ["auto"],
// widths: ["auto"],
defaultAttributes: {
loading: "lazy",
decoding: "async",
},
});
eleventyConfig.addShortcode("image", async function (src, alt, widths = [300, 600], sizes = "100vw") {
let metadata = await Image(`${src}`, {
widths,
formats: ["avif", "jpeg"],
urlPath: "/media/processed",
outputDir: "./src/media/processed",
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
return Image.generateHTML(metadata, imageAttributes);
});
// Minify HTML
if (isProd) {
eleventyConfig.addTransform("htmlmin", function (content) {
if ((this.page.outputPath || "").endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
// // Alpine.js:
// ignoreCustomFragments: [/\s+x-[\w\-.:]+/g],
// minifyJS: false,
});
return minified;
}
return content;
});
}
return {
dir: {
input: "src",
output: "_site",
layouts: "/includes/layouts",
includes: "/includes/partials",
data: "/includes/data"
}
};
};