generated from binyamin/eleventy-garden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.common.js
52 lines (43 loc) · 1.4 KB
/
.eleventy.common.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
const { DateTime } = require('luxon');
module.exports.commonConfig = function (eleventyConfig) {
eleventyConfig.addFilter('simpleDate', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toLocaleString(
DateTime.DATE_MED,
);
});
eleventyConfig.addFilter('outputIfNotEqualTo', (dateObj, othDateObj) => {
if (
DateTime.fromJSDate(dateObj).toMillis() ===
DateTime.fromJSDate(othDateObj).toMillis()
) {
return;
}
return `Updated: ${DateTime.fromJSDate(dateObj, {
zone: 'utc',
}).toLocaleString(DateTime.DATE_MED)}`;
});
eleventyConfig.addFilter('updatedDate', (post) => {
return post.data.updated ? post.data.updated : post.data.page.date;
});
eleventyConfig.addFilter(
'newestCollectionUpdatedDate',
(collection, emptyFallbackDate) => {
if (!collection || !collection.length) {
return emptyFallbackDate || new Date();
}
return new Date(
Math.max(
...collection.map((item) =>
item.data.updated ? item.data.updated : item.data.page.date,
),
),
);
},
);
eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`);
eleventyConfig.addCollection('garden', function (collection) {
return collection.getFilteredByGlob(['garden/**/*.md', 'index.md']);
});
eleventyConfig.setUseGitIgnore(false);
return eleventyConfig;
};