-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
91 lines (74 loc) · 2.23 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
const format = require('date-fns/format');
// Others (e.g. WFH) don't count towards the total
const ELIGIBLE_STATES = ['yes', 'no'];
const TIERS = [
{
threshold: 0,
foregroundColor: 'black',
backgroundColor: 'linear-gradient(#25d49d, #0CBB84)',
},
{
threshold: 10,
foregroundColor: 'black',
backgroundColor: 'linear-gradient(#E63946, #D00000)',
},
{
threshold: 20,
},
];
function streaks(dayArray) {
return dayArray.reduce(([current, max], day) => {
const realState = day.state === 'everyoneelse' ? 'no' : day.state;
const newCurrent = realState === 'no' ? 0 : (
realState === 'yes' ? current + 1 : current
);
const newMax = Math.max(max, newCurrent);
return [newCurrent, newMax];
}, [0, 0]);
}
module.exports = function(config) {
config.addLiquidFilter('currentStreak', dayArray => {
const [current] = streaks(dayArray);
return current;
});
config.addLiquidFilter('bestStreak', dayArray => {
const [, best] = streaks(dayArray);
return best;
});
config.addLiquidFilter('filterGhosts', dayArray => {
return dayArray.filter(d => d.state !== 'ghost');
});
config.addLiquidFilter('nextTier', streak => {
return TIERS.find(t => t.threshold > streak);
});
config.addLiquidFilter('currentTier', streak => {
return TIERS.slice().reverse().find(t => t.threshold <= streak);
});
config.addLiquidFilter('yesPercentage', dayArray => {
const [yes,elig] = dayArray.reduce(([yesCount,eligibleCount],c) => {
return [yesCount + (c.state === 'yes' ? 1 : 0), eligibleCount + (ELIGIBLE_STATES.includes(c.state) ? 1 : 0)]
}, [0, 0]);
return Math.round(yes / elig * 100);
});
config.addLiquidFilter('chooseImage', (record, allStates) => {
const options = allStates[record.state];
if (Array.isArray(options)) {
return options[(record.total - 1) % options.length];
} else {
return options;
}
});
config.addLiquidFilter('cuteDate', date => {
return format(date, 'MMMM do');
});
config.addLiquidFilter('weekday', date => {
return format(date, 'EEEE').toLowerCase();
});
config.addPassthroughCopy({ "src/assets": "/" });
return {
dir: {
input: "src",
output: "dist",
},
};
}