-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
89 lines (69 loc) · 1.83 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
const CleanCSS = require("clean-css");
const fs = require('fs');
const htmlmin = require('html-minifier');
const prettydata = require('pretty-data');
module.exports = (config) => {
// Data Filters
config.addFilter("sortWithId", function(collection) {
return collection.sort((a,b) => a.data.id - b.data.id)
});
config.addFilter('length', (path) => {
const stats = fs.statSync(path);
return stats.size;
});
// HTML Minification
config.addFilter('htmlmin', (value) => {
return htmlmin.minify(
value, {
removeComments: true,
collapseWhitespace: true
}
);
});
config.addTransform('htmlmin', (content, outputPath) => {
if(outputPath && outputPath.endsWith('.html')) {
const result = htmlmin.minify(
content, {
removeComments: true,
collapseWhitespace: true
}
);
return result;
}
return content;
});
// XML Minification for RSS
config.addTransform('xmlmin', (content, outputPath) => {
if(outputPath && outputPath.endsWith('.xml')) {
return prettydata.pd.xmlmin(content);
}
return content;
});
// Passthrough Copy
config.addPassthroughCopy('src/fonts');
config.addPassthroughCopy('src/scripts');
config.addPassthroughCopy('src/static');
config.addPassthroughCopy('src/posts');
config.addPassthroughCopy('src/authors');
config.addPassthroughCopy('src/admin');
// Minified CSS
config.addFilter("cssmin", function(code) {
return new CleanCSS({}).minify(code).styles;
});
// Config
return {
dir: {
input: 'src',
output: 'dist',
includes: 'includes',
layouts: 'layouts',
data: 'data',
},
dataTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
templateFormats: [
'md', 'njk'
],
};
};