-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
74 lines (62 loc) · 2.42 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
const { DateTime } = require("luxon");
const UglifyJS = require("uglify-es");
module.exports = function(eleventyConfig) {
eleventyConfig.addLayoutAlias("post", "layouts/post.njk");
// Date formatting (human readable)
eleventyConfig.addFilter("ddMMyy", dateObj => {
return DateTime.fromJSDate(dateObj).toFormat("dd.MM.yy");
});
// Ordered biogs
eleventyConfig.addCollection("people", function(collection) {
return collection.getFilteredByGlob("_team/*.md").sort(function(a, b) {
return b.data.weighting - a.data.weighting;
});
});
// Minify JS
eleventyConfig.addFilter("jsmin", function(code) {
let minified = UglifyJS.minify(code);
if (minified.error) {
console.log("UglifyJS error: ", minified.error);
return code;
}
return minified.code;
});
eleventyConfig.addFilter("commission", function(c){
let re = /[^\/]+$/g;
return `<ul class="commission-item">
<li class="commission-by"><a href="${c.site}">${c.by}</a></li>
<li class="commission-title">${c.title}</li>
<li class="commission-note">${c.note}</li>
<li class="commission-video">
<iframe src="https://www.youtube.com/embed/${c.url.match(re)}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</li>
</ul>`
});
eleventyConfig.addFilter("madeWith", function(collection){
let sortedCollection = collection.sort(function (a,b){
return (parseInt(a.year) > parseInt(b.year)) ? 1 :
(parseInt(b.year) > parseInt(a.year)) ? -1 : 0;
}
);
let res = '<ul class="madewith-block">';
sortedCollection.forEach((a) => res +=
`<li class="madewith-item">
<div class="madewith-content">
<h6 class="madewith-title"><a class="madewith-link" href="${a.url}" target="_blank">
${a.name}</a></h6>
<p class="madewith-author">${a.by} (${a.year})</p>
<div class="madewith-overlay">${a.desc}</div>
</div>
</li>`);
return res + '</ul>'
});
// Copy the `img` directory
eleventyConfig.addPassthroughCopy("img");
// Copy the `css` directory
eleventyConfig.addPassthroughCopy("css");
// Copy the `fonts` directory
eleventyConfig.addPassthroughCopy("fonts");
return {
passthroughFileCopy: true
};
};