-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
.eleventy.js
68 lines (58 loc) · 1.73 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
64
65
66
67
68
// HTML minification
const htmlmin = require("html-minifier");
// CSS minification
const CleanCSS = require("clean-css");
// JS minification
const { minify } = require("terser");
// Navigation
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
// Start Eleventy Configuration
module.exports = function (eleventyConfig) {
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
if (outputPath && outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});
eleventyConfig.addFilter("cssmin", function (code) {
return new CleanCSS({}).minify(code).styles;
});
eleventyConfig.addNunjucksAsyncFilter(
"jsmin",
async function (code, callback) {
try {
const minified = await minify(code);
callback(null, minified.code);
} catch (err) {
console.error("Terser error: ", err);
// Fail gracefully.
callback(null, code);
}
},
);
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPassthroughCopy("src/img");
eleventyConfig.addPassthroughCopy("src/apple");
eleventyConfig.addPassthroughCopy("src/favicon.ico");
eleventyConfig.addPassthroughCopy("src/robots.txt");
eleventyConfig.addPassthroughCopy("static");
eleventyConfig.addPassthroughCopy({
"static/ads.txt": "./ads.txt",
});
return {
dir: {
input: "src",
output: "_site",
data: "_data",
},
templateFormats: ["html", "njk", "md", "11ty.js"],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dataTemplateEngine: false,
};
};