-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.js
59 lines (52 loc) 路 1.65 KB
/
filters.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
import { DateTime } from 'luxon';
import urlize from '../urlize.js';
import stringify from '../json-pretty-stringify.js';
const toShortDate = (dateObject) => {
// 10/14/1983
return DateTime.fromISO(dateObject, { zone: 'utc' }).toFormat('MM/dd/yyyy');
};
const toMedDate = (dateObject) => {
// Oct 14, 1983
return DateTime.fromISO(dateObject, { zone: 'utc' }).toFormat(
'MMM dd, yyyy',
);
};
const toFullDate = (dateObject) => {
// October 14, 1983
return DateTime.fromISO(dateObject, { zone: 'utc' }).toFormat(
'MMMM dd, yyyy',
);
};
const toShortDateTime = (dateObject) => {
// 10/14/1983, 10:30 PM
return DateTime.fromISO(dateObject, { zone: 'utc' }).toFormat(
'MM/dd/yyyy, hh:mm a',
);
};
const toMedDateTime = (dateObject) => {
// Oct 14, 1983, 10:30 PM
return DateTime.fromISO(dateObject, { zone: 'utc' }).toFormat(
'MMM dd, yyyy, hh:mm a',
);
};
const toFullDateTime = (dateObject) => {
// October 14, 1983, 10:30 PM
return DateTime.fromISO(dateObject, { zone: 'utc' }).toFormat(
'MMMM dd, yyyy, hh:mm a',
);
};
export const filters = (eleventyConfig) => {
eleventyConfig.addFilter('toShortDate', toShortDate);
eleventyConfig.addFilter('toMedDate', toMedDate);
eleventyConfig.addFilter('toFullDate', toFullDate);
eleventyConfig.addFilter('toShortDateTime', toShortDateTime);
eleventyConfig.addFilter('toMedDateTime', toMedDateTime);
eleventyConfig.addFilter('toFullDateTime', toFullDateTime);
eleventyConfig.addFilter('capitalize', (string) => {
return string.charAt(0).toUpperCase() + string.slice(1);
});
eleventyConfig.addFilter('stringify', (value) => {
return stringify(value, '\t');
});
eleventyConfig.addFilter('url', urlize);
};