-
Notifications
You must be signed in to change notification settings - Fork 12
/
.eleventy.js
83 lines (63 loc) · 2.72 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
const markdownIt = require('markdown-it');
const emoji = require('markdown-it-emoji');
const eleventyPluginFilesMinifier = require('@sherby/eleventy-plugin-files-minifier');
const { comparators } = require('generate-comparators');
const getTwitchChannelEmbed = require('./src/utils/get-twitch-channel-embed');
const getYouTubeVideoEmbed = require('./src/utils/get-youtube-video-embed');
const personUtils = require('./src/utils/person');
const { isAfter, isBefore, format, isToday } = require('date-fns');
const isProduction = process.env.NODE_ENV === 'production';
// It's value taken in scripts(package.json) returned boolean
const isValidTitle = (title = '') => title.trim().length > 2;
const isValidEvent = (event) => isValidTitle(event.data.title);
const byDate = comparators((event) => event.data.date);
module.exports = (eleventyConfig) => {
eleventyConfig.addCollection('events', (collectionApi) => {
return collectionApi.getFilteredByGlob('./src/schedule/*.md');
});
eleventyConfig.addCollection('pastEvents', (collectionApi) => {
return collectionApi
.getFilteredByGlob('./src/schedule/*.md')
.filter((event) => isValidEvent(event) && isBefore(new Date(event.data.date), new Date()));
});
eleventyConfig.addCollection('upcomingEvents', (collectionApi) => {
const serverEvents = collectionApi
.getFilteredByGlob('./src/schedule/*.md')
.filter((event) => isValidEvent(event) && isAfter(new Date(event.data.date), new Date()));
const someAnticsStreams = collectionApi.items[0].data.someAntics;
return [...serverEvents, ...someAnticsStreams].sort(byDate.asc);
});
let markdown = markdownIt({
typographer: true,
html: true,
});
markdown.use(emoji);
eleventyConfig.setLibrary('md', markdown);
eleventyConfig.addPassthroughCopy('src/assets');
eleventyConfig.addPassthroughCopy('src/css');
eleventyConfig.addPassthroughCopy('src/js');
eleventyConfig.addPassthroughCopy('_redirects');
eleventyConfig.addFilter('asDateOnly', function (date) {
return format(new Date(date), 'PP');
});
eleventyConfig.addFilter('toISOString', function (date) {
return new Date(date).toISOString();
});
eleventyConfig.addShortcode('twitch', getTwitchChannelEmbed);
eleventyConfig.addShortcode('youtube-video', getYouTubeVideoEmbed);
eleventyConfig.addFilter('asDateTime', function (date) {
return `${format(new Date(date), 'MMM d, yyyy p')} PST`;
});
eleventyConfig.addFilter('pageSourcePath', function (inputPath) {
return `https://github.com/LunchDevCommunity/community-calendar/edit/main/${inputPath.replace('./', '')}`;
});
eleventyConfig.addFilter('personAvatar', personUtils.getAvatarUrl);
if (isProduction) {
eleventyConfig.addPlugin(eleventyPluginFilesMinifier);
}
return {
dir: {
input: './src/',
},
};
};