forked from philhawksworth/eleventyone
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
66 lines (50 loc) · 1.78 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
const fs = require("fs");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
module.exports = function(config) {
// A useful way to reference the context we are runing eleventy in
let env = process.env.ELEVENTY_ENV;
// Layout aliases can make templates more portable
config.addLayoutAlias('default', 'layouts/base.njk');
// Add some utility filters
config.addFilter("squash", require("./src/utils/filters/squash.js") );
config.addFilter("dateDisplay", require("./src/utils/filters/date.js") );
// add support for syntax highlighting
config.addPlugin(syntaxHighlight);
// minify the html output
config.addTransform("htmlmin", require("./src/utils/minify-html.js"));
// compress and combine js files
config.addFilter("jsmin", function(code) {
const UglifyJS = require("uglify-js");
let minified = UglifyJS.minify(code);
if( minified.error ) {
console.log("UglifyJS error: ", minified.error);
return code;
}
return minified.code;
});
// pass some assets right through
config.addPassthroughCopy("./src/site/images");
if (fs.existsSync("./src/site/admin")) {
config.addPassthroughCopy("./src/site/admin");
}
config.addCollection("menus", function(collection) {
return collection.getAll().filter(function(item) {
return item.data.menus && item.data.menus.title
}).sort(function(a, b) {
return a.data.menus.weight - b.data.menus.weight
});
});
// make the seed target act like prod
env = (env=="seed") ? "prod" : env;
return {
dir: {
input: "src/site",
output: "dist",
data: `_data/${env}`
},
templateFormats : ["njk", "md", "11ty.js"],
htmlTemplateEngine : "njk",
markdownTemplateEngine : "njk",
passthroughFileCopy: true
};
};