-
Notifications
You must be signed in to change notification settings - Fork 4
/
.eleventy.js
90 lines (81 loc) · 2.36 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const moment = require("moment-timezone");
const markdownIt = require("markdown-it");
const purifycss = require("purify-css");
const htmlminifier = require("html-minifier");
const md = new markdownIt();
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("site/img");
eleventyConfig.addPassthroughCopy("site/fonts");
eleventyConfig.addPassthroughCopy("site/styles.css");
eleventyConfig.addPassthroughCopy("site/script.js");
eleventyConfig.addPassthroughCopy("site/sw.js");
eleventyConfig.addPassthroughCopy("site/site.webmanifest");
eleventyConfig.addPassthroughCopy("site/browserconfig.xml");
eleventyConfig.addPassthroughCopy("site/_redirects");
eleventyConfig.addNunjucksFilter("date", function(
date,
format = "YYYY-MM-DD"
) {
return moment(date).format(format);
});
eleventyConfig.addNunjucksFilter("markdown", function(string) {
return md.render(string);
});
eleventyConfig.addTransform("purifycss", async function(content, outputPath) {
if (outputPath.endsWith(".html")) {
return new Promise(resolve => {
purifycss(
content,
["build/styles.css"],
{
minify: true
},
css => {
resolve(
content.replace(
'<link rel="stylesheet" href="/styles.css">',
`<style>${css}</style>`
)
);
}
);
});
}
return content;
});
eleventyConfig.addTransform("htmlminifier", async function(
content,
outputPath
) {
if (outputPath.endsWith(".html")) {
return htmlminifier.minify(content, {
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true
});
}
return content;
});
return {
templateFormats: ["njk", "md", "11ty.js"],
pathPrefix: "/",
markdownTemplateEngine: "liquid",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
passthroughFileCopy: true,
dir: {
input: "site",
includes: "../includes",
data: "../data",
output: "build"
}
};
};