-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.eleventy.tweets.js
71 lines (65 loc) · 1.27 KB
/
.eleventy.tweets.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
const twitter_text = require('twitter-text');
const {common:commonConfig} = require('./.eleventy.common-config.js');
module.exports = (config) => {
commonConfig(config);
config.addFilter('tweet', (tweet) => {
return twitter_text.autoLink(
tweet.data.text,
{
urlEntities: tweet.data.entities?.urls ?? [],
}
).replace(/rel="nofollow"/g, 'rel="nofollow noopener"').replace('\n', '<br>\n');
});
config.addFilter('format_date', (date_str) => {
const date = new Date(date_str);
const ordinals = [
'th', // 0th
'st', // 1st
'nd', // 2nd
'rd', // 3rd
'th', // 4th
'th', // 5th
'th', // 6th
'th', // 7th
'th', // 8th
'th', // 9th
'th', // 10th
'th', // 11th
'th', // 12th
'th', // 13th
'th', // 14th
'th', // 15th
'th', // 16th
'th', // 17th
'th', // 18th
'th', // 19th
];
return (
date.toLocaleDateString(
'en-GB',
{ month: 'long'}
)
+ ' '
+ date.getDate()
+ ordinals[date.getDate() % 20]
+ ', '
+ date.toLocaleDateString(
'en-GB',
{ year: 'numeric'}
)
);
});
return Object.assign(
{},
require('./.eleventy.js'),
{
dir: {
data: '../data',
input: './11ty/tweets/',
layouts: '../layouts',
includes: '../includes',
output: './src',
}
}
);
};