-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eleventy.js
87 lines (70 loc) · 2.21 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
const eleventyNavigationPlugin = require('@11ty/eleventy-navigation');
const markdown = require('./lib/markdown');
const slugify = require('slugify');
const svgContents = require('eleventy-plugin-svg-contents');
function formatDate(date, options = {}) {
if (!(date instanceof Date)) {
date = new Date(date);
}
if (!('timeZone' in options)) {
options.timeZone = 'UTC';
}
return date.toLocaleDateString(options.locale || 'en-US', options);
}
function formatTime(date, options = {}) {
if (!(date instanceof Date)) {
date = new Date(date);
}
return date.toLocaleTimeString(options.locale || 'en-US', options);
}
module.exports = function (eleventy) {
eleventy.addPlugin(eleventyNavigationPlugin);
eleventy.setLibrary('md', markdown);
eleventy.addFilter('spanner', (text) =>
text
.split('')
.map((i) => `<span>${i}</span>`)
.join(''),
);
eleventy.addFilter('speakers', (session, speakers) =>
// Sometimes the data for a session's speakers includes an ID, sometimes it's just the ID
session.speakers.map((s) => speakers.find((s2) => s2.id === s.id || s2.id === s)),
);
eleventy.addFilter('date', formatDate);
eleventy.addFilter('time', formatTime);
eleventy.addFilter('md', (text) => markdown.render(text));
eleventy.addFilter('slugify', (text) =>
slugify(text, { lower: true, remove: /[_*+~.()'"!:@]/g, strict: true }),
);
eleventy.addShortcode(
'date',
(date, options = {}) =>
`<span data-date="${date}" data-format='${JSON.stringify(options)}'>${formatDate(
date,
options,
)}</span>`,
);
eleventy.addShortcode(
'time',
(date, options = {}) =>
`<span data-time="${date}" data-format='${JSON.stringify(options)}'>${formatTime(
date,
options,
)}</span>`,
);
eleventy.addShortcode('timezone', () => `<span data-timezone="UTC">UTC</span>`);
eleventy.addPlugin(svgContents);
return {
dir: {
input: 'src',
output: 'src',
data: '../_data',
includes: '../templates/_includes',
layouts: '../templates/_layouts',
},
dataTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
templateEngineOverride: 'njk',
};
};