-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path.eleventy.js
63 lines (55 loc) · 1.69 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
import { minify } from "html-minifier-terser";
const createSearchParam = (params) => {
const urlParams = new URLSearchParams();
Object.entries(params).forEach(([key, value]) => {
urlParams.append(key, value);
});
return urlParams.toString();
};
export default function (eleventyConfig) {
eleventyConfig.addLiquidFilter("title", function (value) {
return value.charAt(0).toUpperCase() + value.slice(1);
});
eleventyConfig.addLiquidFilter("stringify", function (value) {
return JSON.stringify(value);
});
eleventyConfig.addLiquidFilter("redirectExamplePath", function (redirect) {
return `/redirect/${
redirect.redirect
}/${redirect.example ? `?${createSearchParam(redirect.example)}` : ""}`;
});
eleventyConfig.addLiquidFilter("version", function (value) {
if (value.startsWith("supervisor-")) {
return `Home Assistant Supervisor ${value.replace("supervisor-", "")}`;
}
if (value.startsWith("core-")) {
return `Home Assistant Core ${value.replace("core-", "")}`;
}
return `Home Assistant Core ${value}`;
});
if (process.env.NODE_ENV === "production") {
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
if (outputPath.endsWith(".html")) {
let minified = minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: {
safari10: false,
ecma: undefined,
output: { comments: false },
},
});
return minified;
}
return content;
});
}
return {
dir: {
input: "src-11ty",
output: "dist",
},
};
};