forked from FH-Potsdam/teaching-parametric-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
104 lines (85 loc) · 2.69 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const pluginTOC = require('eleventy-plugin-toc');
const moment = require('moment');
module.exports = function(config) {
// A useful way to reference the context we are runing eleventy in
let env = process.env.ELEVENTY_ENV;
// custom collection of 3d previews to generate index/json files
config.addCollection("preview3d", function(collection) {
return collection.getFilteredByGlob("./src/site/code/3d/*.md");
});
// Layout aliases can make templates more portable
config.addLayoutAlias('default', 'layouts/base.njk');
config.addLayoutAlias('home', 'layouts/home.njk');
// add support for syntax highlighting
config.addPlugin(syntaxHighlight);
// add navigation data object
config.addPlugin(eleventyNavigationPlugin);
config.addPlugin(pluginTOC, {
tags: ['h2'],
wrapper: '',
ul: true
});
config.addFilter("pageNav", function(navigation, page, locale) {
const pageNav = {
back: null,
next: null
};
let foundPage = false;
const check = (entry) => {
if (entry.url !== page.url && !foundPage) {
pageNav.back = entry;
}
if (foundPage && pageNav.next === null) {
pageNav.next = entry;
}
if (entry.url === page.url) {
foundPage = true;
}
};
navigation.forEach(nav => {
if (nav.key === locale){
nav.children.forEach(child => {
check(child);
child.children.forEach(entry => {
check(entry);
});
});
}
});
return pageNav;
});
// 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;
});
config.addNunjucksFilter("date", function (date, format, locale) {
locale = locale ? locale : "en";
moment.locale(locale);
return moment(date).format(format);
});
// pass some assets right through
config.addPassthroughCopy("./src/site/images");
config.addPassthroughCopy("./src/site/fonts");
config.addPassthroughCopy("./src/site/js");
config.addPassthroughCopy({"./src/site/_includes/roots" : "."});
// make the seed target act like prod
env = (env=="seed") ? "prod" : env;
return {
dir: {
input: "src/site",
output: "dist"
},
templateFormats : ["njk", "md", "11ty.js"],
htmlTemplateEngine : "njk",
markdownTemplateEngine : "njk",
passthroughFileCopy: true
};
};