This repository has been archived by the owner on Jan 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
51 lines (43 loc) · 1.63 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
const htmlmin = require("html-minifier");
const { DateTime } = require("luxon");
module.exports = function (eleventyConfig) {
// Folders to copy to build dir (See. 1.1)
eleventyConfig.addPassthroughCopy("src/static");
if (process.env.ELEVENTY_ENV === 'production') {
// Minify HTML (including inlined CSS and JS)
eleventyConfig.addTransform("compressHTML", function (content, outputPath) {
if (outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true
});
return minified;
}
return content;
});
}
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd');
});
eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(new Date(dateObj), { zone: 'utc' }).toFormat("dd LLL yyyy");
});
eleventyConfig.addFilter("w3cDate", function (date) {
return date.toISOString();
});
return {
dir: {
input: "src/",
output: "dist",
includes: "_includes"
},
templateFormats: ["html", "md", "njk"],
htmlTemplateEngine: "njk",
// 1.1 Enable eleventy to pass dirs specified above
passthroughFileCopy: true
};
};