-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.eleventy.js
More file actions
505 lines (437 loc) · 15.2 KB
/
Copy path.eleventy.js
File metadata and controls
505 lines (437 loc) · 15.2 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
const { DateTime } = require('luxon');
const readingTime = require('eleventy-plugin-reading-time');
const pluginRss = require('@11ty/eleventy-plugin-rss');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const fs = require('fs');
const path = require('path');
const htmlmin = require("html-minifier");
const isDev = process.env.ELEVENTY_ENV === 'development';
const isProd = process.env.ELEVENTY_ENV === 'production'
const manifestPath = path.resolve(
__dirname,
'public',
'assets',
'manifest.json'
);
const manifest = isDev
? {
'main.js': '/assets/main.js',
'main.css': '/assets/main.css',
}
: JSON.parse(fs.readFileSync(manifestPath, { encoding: 'utf8' }));
const { execSync } = require('child_process')
const embedYouTube = require("eleventy-plugin-youtube-embed");
const brokenLinksPlugin = require("eleventy-plugin-broken-links");
// Anchor links
const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');
const slugify = require("slugify");
const yaml = require('js-yaml');
//Eleventy Configurations
module.exports = function (eleventyConfig) {
eleventyConfig.addDataExtension("yaml", (contents) => yaml.load(contents));
// Those live in src/js since they are code, not data, so they have to be
// registered as global data manually.
eleventyConfig.addGlobalData("talkLocations", require('./src/js/talkLocations.js'));
eleventyConfig.addGlobalData("devrelPlaylist", require('./src/js/devrelPlaylist.js'));
eleventyConfig.addPlugin(readingTime);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(syntaxHighlight);
//Replace Markdown with custom configurations
const md = markdownIt({
html: true,
linkify: true,
typographer: true
}).use(markdownItAnchor, {
level: [2, 3, 4, 5, 6],
slugify: (str) =>
slugify(str, {
lower: true,
strict: true,
remove: /["]/g,
}),
permalink: markdownItAnchor.permalink.linkInsideHeader({
symbol: ' #',
placement: 'after',
ariaHidden: true,
class: 'header-anchor',
}),
});
eleventyConfig.setLibrary("md", md);
//Search: pageFind
eleventyConfig.on('eleventy.after', () => {
execSync(`npx pagefind --site public --glob \"**/*.html\"`, { encoding: 'utf-8' })
})
//YouTube embedded plugin
eleventyConfig.addPlugin(embedYouTube);
//Broken links plugins
eleventyConfig.addPlugin(brokenLinksPlugin, {
forbidden: "error",
//redirect: "error",
//broken: "error",
exclude: [
"https://vivo-us.com*"
]
});
// setup mermaid markdown highlighter
const highlighter = eleventyConfig.markdownHighlighter;
eleventyConfig.addMarkdownHighlighter((str, language) => {
if (language === 'mermaid') {
return `<pre class="mermaid">${str}</pre>`;
}
return highlighter(str, language);
});
eleventyConfig.setDataDeepMerge(true);
eleventyConfig.addPassthroughCopy({ 'src/images': 'images' });
eleventyConfig.setBrowserSyncConfig({ files: [manifestPath] });
eleventyConfig.addShortcode('bundledcss', function () {
return manifest['main.css']
? `<link href="${manifest['main.css']}" rel="stylesheet" />`
: '';
});
eleventyConfig.addShortcode('bundledjs', function () {
return manifest['main.js']
? `<script src="${manifest['main.js']}"></script>`
: '';
});
eleventyConfig.addFilter('excerpt', (post) => {
const content = post.replace(/(<([^>]+)>)/gi, '');
return content.substr(0, content.lastIndexOf(' ', 200)) + '...';
});
eleventyConfig.addFilter('readableDate', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat(
'dd LLL yyyy'
);
});
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd');
});
eleventyConfig.addFilter('dateToIso', (dateString) => {
return new Date(dateString).toISOString()
});
eleventyConfig.addFilter('head', (array, n) => {
if (n < 0) {
return array.slice(n);
}
return array.slice(0, n);
});
eleventyConfig.addCollection('tagList', function (collection) {
let tagSet = new Set();
collection.getAll().forEach(function (item) {
if ('tags' in item.data) {
let tags = item.data.tags;
tags = tags.filter(function (item) {
switch (item) {
case 'all':
case 'nav':
case 'post':
case 'posts':
return false;
}
return true;
});
for (const tag of tags) {
tagSet.add(tag);
}
}
});
return [...tagSet];
});
eleventyConfig.addFilter('pageTags', (tags) => {
const generalTags = ['all', 'nav', 'post', 'posts'];
return tags
.toString()
.split(',')
.filter((tag) => {
return !generalTags.includes(tag);
});
});
// Add .htaccess
eleventyConfig.addPassthroughCopy({ 'src/.htaccess': '.htaccess' });
// Add slides
eleventyConfig.addPassthroughCopy({ 'src/slides/': 'slides/' });
// Add docs
eleventyConfig.addPassthroughCopy({ 'src/docs/': 'docs/' });
// Vendored bundles for the speaking map
eleventyConfig.addPassthroughCopy({ 'src/vendor': 'vendor' });
//Pinned posts
//Usage:
//
//pinned: true
//
eleventyConfig.addCollection("postsSorted", function(collectionApi) {
const allPosts = collectionApi.getFilteredByTag("posts").slice().reverse(); // newest first
const pinned = allPosts.filter(post => post.data.pinned === true);
const unpinned = allPosts.filter(post => !post.data.pinned);
return [...pinned, ...unpinned];
});
// Add custom filter to group talks
eleventyConfig.addFilter("groupTalksByYear", function(talks) {
if (!talks || !Array.isArray(talks)) {
return {
upcoming: [],
past: {},
upcomingLivestreams: [],
pastLivestreams: {},
upcomingPodcasts: [],
pastPodcasts: {},
upcomingWebinars: [],
pastWebinars: {},
upcomingInterviews: [],
pastInterviews: {},
upcomingTutorials: [],
pastTutorials: {},
stats: { total: 0, past: 0, upcoming: 0, cities: 0, countries: 0, keynotes: 0, panels: 0, events: 0 },
livestreamStats: { total: 0, past: 0, upcoming: 0 },
podcastStats: { total: 0, past: 0, upcoming: 0 },
webinarStats: { total: 0, past: 0, upcoming: 0 },
interviewStats: { total: 0, past: 0, upcoming: 0 },
tutorialStats: { total: 0, past: 0, upcoming: 0 }
};
}
const now = new Date();
// Collects past talk/panel/keynote dates grouped by event name, used to
// count unique events (same name with same or consecutive days = one event).
const eventDatesByName = {};
const result = {
upcoming: [],
past: {},
upcomingLivestreams: [],
pastLivestreams: {},
upcomingPodcasts: [],
pastPodcasts: {},
upcomingWebinars: [],
pastWebinars: {},
upcomingInterviews: [],
pastInterviews: {},
upcomingTutorials: [],
pastTutorials: {},
stats: {
total: 0,
past: 0,
upcoming: 0,
cities: new Set(),
countries: new Set(),
keynotes: 0,
panels: 0,
events: 0
},
livestreamStats: {
total: 0,
past: 0,
upcoming: 0
},
podcastStats: {
total: 0,
past: 0,
upcoming: 0
},
webinarStats: {
total: 0,
past: 0,
upcoming: 0
},
interviewStats: {
total: 0,
past: 0,
upcoming: 0
},
tutorialStats: {
total: 0,
past: 0,
upcoming: 0
}
};
talks.forEach(talk => {
// A talk without a date (or with one we can't parse) isn't scheduled yet:
// it counts as upcoming rather than landing in a NaN year.
const parsed = talk.date ? new Date(talk.date + 'T23:59:59Z') : null;
const talkDate = parsed && !isNaN(parsed.getTime()) ? parsed : null;
const isUpcoming = !talkDate || talkDate.getTime() > now.getTime();
const isLivestream = talk.type && talk.type.toLowerCase() === 'livestream';
const isPodcast = talk.type && talk.type.toLowerCase() === 'podcast';
const isWebinar = talk.type && talk.type.toLowerCase() === 'webinar';
const isInterview = talk.type && talk.type.toLowerCase() === 'interview';
const isTutorial = talk.type && talk.type.toLowerCase() === 'tutorial';
if (isLivestream) {
result.livestreamStats.total++;
if (isUpcoming) {
result.upcomingLivestreams.push(talk);
result.livestreamStats.upcoming++;
} else {
const year = talkDate.getFullYear();
if (!result.pastLivestreams[year]) {
result.pastLivestreams[year] = [];
}
result.pastLivestreams[year].push(talk);
result.livestreamStats.past++;
}
} else if (isPodcast) {
result.podcastStats.total++;
if (isUpcoming) {
result.upcomingPodcasts.push(talk);
result.podcastStats.upcoming++;
} else {
const year = talkDate.getFullYear();
if (!result.pastPodcasts[year]) {
result.pastPodcasts[year] = [];
}
result.pastPodcasts[year].push(talk);
result.podcastStats.past++;
}
} else if (isWebinar) {
result.webinarStats.total++;
if (isUpcoming) {
result.upcomingWebinars.push(talk);
result.webinarStats.upcoming++;
} else {
const year = talkDate.getFullYear();
if (!result.pastWebinars[year]) {
result.pastWebinars[year] = [];
}
result.pastWebinars[year].push(talk);
result.webinarStats.past++;
}
} else if (isInterview) {
result.interviewStats.total++;
if (isUpcoming) {
result.upcomingInterviews.push(talk);
result.interviewStats.upcoming++;
} else {
const year = talkDate.getFullYear();
if (!result.pastInterviews[year]) {
result.pastInterviews[year] = [];
}
result.pastInterviews[year].push(talk);
result.interviewStats.past++;
}
} else if (isTutorial) {
result.tutorialStats.total++;
if (isUpcoming) {
result.upcomingTutorials.push(talk);
result.tutorialStats.upcoming++;
} else {
const year = talkDate.getFullYear();
if (!result.pastTutorials[year]) {
result.pastTutorials[year] = [];
}
result.pastTutorials[year].push(talk);
result.tutorialStats.past++;
}
} else {
result.stats.total++;
if (isUpcoming) {
result.upcoming.push(talk);
result.stats.upcoming++;
} else {
const year = talkDate.getFullYear();
if (!result.past[year]) {
result.past[year] = [];
}
result.past[year].push(talk);
result.stats.past++;
const talkType = talk.type ? talk.type.toLowerCase() : '';
if (talkType === 'keynote') {
result.stats.keynotes++;
}
if (talkType === 'panel') {
result.stats.panels++;
}
if (talk.city) {
result.stats.cities.add(talk.city);
if (talk.city.includes(',')) {
result.stats.countries.add(talk.city.split(',').pop().trim());
}
}
if (talk.name && (talkType === 'talk' || talkType === 'panel' || talkType === 'keynote')) {
if (!eventDatesByName[talk.name]) {
eventDatesByName[talk.name] = [];
}
eventDatesByName[talk.name].push(talk.date);
}
}
}
});
result.stats.cities = result.stats.cities.size;
result.stats.countries = result.stats.countries.size;
// Count unique events: within each event name, dates on the same or
// consecutive days belong to one event; a gap of more than one day starts
// a new one (e.g. the same conference held in different years).
Object.values(eventDatesByName).forEach(dates => {
const days = dates
.map(date => new Date(date + 'T00:00:00Z').getTime())
.sort((a, b) => a - b);
let count = 1;
for (let i = 1; i < days.length; i++) {
const diffDays = Math.round((days[i] - days[i - 1]) / 86400000);
if (diffDays > 1) {
count++;
}
}
result.stats.events += count;
});
// Events without a date come first in the upcoming lists, before the ones
// with a known future date.
const undatedFirst = (events) => [
...events.filter(event => !event.date),
...events.filter(event => event.date)
];
result.upcoming = undatedFirst(result.upcoming);
result.upcomingLivestreams = undatedFirst(result.upcomingLivestreams);
result.upcomingPodcasts = undatedFirst(result.upcomingPodcasts);
result.upcomingWebinars = undatedFirst(result.upcomingWebinars);
result.upcomingInterviews = undatedFirst(result.upcomingInterviews);
result.upcomingTutorials = undatedFirst(result.upcomingTutorials);
result.pastYears = Object.keys(result.past).sort((a, b) => b - a);
result.pastLivestreamYears = Object.keys(result.pastLivestreams).sort((a, b) => b - a);
result.pastPodcastYears = Object.keys(result.pastPodcasts).sort((a, b) => b - a);
result.pastWebinarYears = Object.keys(result.pastWebinars).sort((a, b) => b - a);
result.pastInterviewYears = Object.keys(result.pastInterviews).sort((a, b) => b - a);
result.pastTutorialYears = Object.keys(result.pastTutorials).sort((a, b) => b - a);
return result;
});
// Add date formatting filter
eleventyConfig.addFilter("formatTalkDate", function(dateString) {
const months =['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const date = dateString ? new Date(dateString) : null;
// No date yet, or one we can't parse: don't render NaN placeholders.
if (!date || isNaN(date.getTime())) return 'TBD';
const month = months[date.getMonth()];
const day = date.getUTCDate();
const year = date.getFullYear();
return `${day} ${month} ${year}`.toUpperCase();
});
// Minify HTML output
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
if (outputPath && outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
// Social media image
eleventyConfig.addFilter("getFirstImage", function(content) {
if (!content) return null;
// Match img tags and extract src
const imgRegex = /<img\s+[^>]*src=["']([^"']+)["'][^>]*>/i;
const match = content.match(imgRegex);
return match ? match[1] : null;
});
return {
dir: {
input: 'src',
output: 'public',
includes: 'includes',
data: 'data',
layouts: 'layouts'
},
passthroughFileCopy: true,
templateFormats: ['html', 'njk', 'md'],
htmlTemplateEngine: 'njk',
markdownTemplateEngine: 'njk',
};
};