-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.mjs
83 lines (75 loc) · 2.59 KB
/
eleventy.config.mjs
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
import fs from "node:fs";
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import eleventyPluginTinyHTML from "@sardine/eleventy-plugin-tinyhtml";
import CleanCSS from "clean-css";
import automaticNoopener from "eleventy-plugin-automatic-noopener";
const IS_PRODUCTION = process.env.NODE_ENV === "production";
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
export default async function (eleventyConfig) {
// Directories
eleventyConfig.setInputDirectory("./src");
eleventyConfig.setOutputDirectory("./_site");
eleventyConfig.setLayoutsDirectory("_layouts");
eleventyConfig.setIncludesDirectory("_includes");
eleventyConfig.addPassthroughCopy("./src/css");
eleventyConfig.addPassthroughCopy("./src/img");
// Sets Liquid options
eleventyConfig.setLiquidOptions({
dynamicPartials: false,
strictFilters: true,
});
// Date formatter filter
eleventyConfig.addFilter("postDate", (dateObj) => {
return dateObj.toLocaleString(undefined, {
year: "numeric",
month: "numeric",
day: "numeric",
});
});
// Syntax highlighting support
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(automaticNoopener);
// Minification
if (IS_PRODUCTION) {
eleventyConfig.addPlugin(eleventyPluginTinyHTML, {
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
conservativeCollapse: true,
decodeEntities: true,
includeAutoGeneratedTags: false,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
preventAttributesEscaping: true,
processConditionalComments: true,
removeAttributeQuotes: false,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true,
trimCustomFragments: true,
useShortDoctype: true,
});
}
// CSS minification in production
if (IS_PRODUCTION) {
eleventyConfig.on("afterBuild", () => {
const inputFile = "./src/css/index.css";
const input = fs.readFileSync(inputFile, "utf8");
const output = new CleanCSS().minify(input);
// Minifies the CSS file
fs.writeFile("./_site/css/index.css", output.styles, (error) => {
if (error) {
// biome-ignore lint/suspicious/noConsole: We don't need a custom logger for this CLI
console.error(`Error minifying index.css: ${error}`);
return;
}
});
});
}
}