-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
74 lines (62 loc) · 1.88 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 { find } = require("geo-tz");
const { chain, groupBy, toPairs, value } = require("lodash");
const GPS_DEFAULT = [40.76, -73.95];
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({ "*.{woff2,jpg,css}": "" });
eleventyConfig.addPassthroughCopy({ meta: "meta" });
eleventyConfig.addPassthroughCopy({ 'og/images': "img" });
eleventyConfig.addFilter("timezonedDate", (str, coords) => {
const options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
minute: "numeric",
timeZoneName: "long",
};
if (!coords) coords = GPS_DEFAULT;
const timeZone = find(...coords);
const date = new Date(str).toLocaleDateString("en-US", {
timeZone,
...options,
});
return date;
});
eleventyConfig.addFilter("urlDate", (str) => {
const date = new Date(str);
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return `${year} ${`${month}`.padStart(2, "0")} ${`${day}`.padStart(
2,
"0"
)}`;
});
eleventyConfig.addFilter("shortDate", (str) => {
const date = new Date(str);
return date.toLocaleDateString("en-US", {
month: "long",
day: "numeric",
});
});
eleventyConfig.addFilter("encodeURIComponent", (str) => {
return encodeURIComponent(str);
});
eleventyConfig.addFilter("contentToDescription", (str) => {
return str.replace(/\r|\n|\r\n/g, " ❡ ");
});
eleventyConfig.addCollection("postsByYear", (collectionApi) =>
// Use lodash methods to sort posts by year
// Turns { year: [posts] } format into [ year, [posts] ] ]
chain(collectionApi.getFilteredByTag("posts"))
.groupBy((post) => {
return new Date(post.date).getFullYear();
})
.toPairs()
.value()
);
return {
htmlTemplateEngine: "njk",
};
};