forked from machinaeXphilip/berlin-open-source-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
79 lines (66 loc) · 2.21 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
module.exports = function (eleventyConfig) {
// This allows Eleventy to watch for file changes during local development.
eleventyConfig.setUseGitIgnore(false);
eleventyConfig.setDataDeepMerge(true);
eleventyConfig.addPassthroughCopy("src/assets/fonts");
eleventyConfig.addPassthroughCopy("src/assets/images");
eleventyConfig.addPassthroughCopy("src/assets/css/style.compiled.css");
eleventyConfig.addPassthroughCopy("src/assets/js");
eleventyConfig.addPassthroughCopy({ "src/assets/common": "." });
eleventyConfig.addWatchTarget("./src/assets/css/style.compiled.css");
eleventyConfig.addCollection(
"tagList",
require("./src/_filters/getTagList.js")
);
eleventyConfig.addCollection("navItems", function (collectionApi) {
const navItems = collectionApi.getFilteredByTag("nav");
const sortedNavItems = navItems.sort((a, b) => {
const getPositionTag = (item) => {
return item.data.tags.find((tag) => tag.startsWith("nav-item-"));
};
const aTag = getPositionTag(a);
const bTag = getPositionTag(b);
if (aTag < bTag) return -1;
if (aTag > bTag) return 1;
return 0;
});
return sortedNavItems;
});
eleventyConfig.addFilter("relativeTime", (date) => {
const delta = Math.round((new Date() - new Date(date)) / 1000);
const minute = 60,
hour = minute * 60,
day = hour * 24,
week = day * 7,
month = week * 4,
year = month * 12;
switch (true) {
case delta <= week:
return "In der letzten Woche";
case delta <= month:
return "Im letzten Monat";
case delta <= month * 2:
return "Vor 2 Monaten";
case delta <= month * 3:
return "Vor 3 Monaten";
case delta <= month * 6:
return "Vor über 3 Monaten";
case delta <= year:
return "Vor über 6 Monaten";
case delta <= year * 2:
return "Vor über einem Jahr";
case delta <= year * 3:
return "Vor über zwei Jahren";
default:
return `${new Date(date).toLocaleDateString("de-DE")}`;
}
});
return {
dir: {
data: "_data",
input: "src",
output: "_site", // this is the default
},
passthroughFileCopy: true,
};
};