This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
forked from chron/squad-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
59 lines (46 loc) · 1.68 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
require('dotenv').config();
//console.log(process.env.GITHUB_TOKEN);
const formatDistance = require('date-fns/formatDistance');
const format = require('date-fns/format');
const parseISO = require('date-fns/parseISO');
const Image = require("@11ty/eleventy-img");
const USERS = require('./_data/users'); // TODO: better way to load this?
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy('css');
eleventyConfig.addPassthroughCopy({ public: '/' });
eleventyConfig.addFilter('debug', function(input) {
return JSON.stringify(input, null, 2);
});
eleventyConfig.addFilter('timedist', function(input) {
if (!input) { return ''; }
return formatDistance(parseISO(input), new Date)
});
eleventyConfig.addFilter('shortDate', function(input) {
if (!input) { return ''; }
return format(parseISO(input), 'MMM d');
});
eleventyConfig.addFilter('nickname', function(githubLogin) {
return USERS.find(u => u.githubLogin === githubLogin)?.nickname || githubLogin;
});
eleventyConfig.addNunjucksAsyncShortcode('avatar', async function(userName) {
if (!userName) { return ''; }
// input.avatar is the URL of their github avatar, but those are kinda boring?
const avatarUrl = `https://avatars.dicebear.com/api/bottts/${userName}.svg`;
const metadata = await Image(avatarUrl, {
widths: [80],
formats: ['png'],
outputDir: './_site/img/',
});
const imageAttributes = {
alt: `Avatar of ${userName}`,
title: userName,
sizes: [40],
loading: 'lazy',
decoding: 'async',
};
return Image.generateHTML(metadata, imageAttributes);
});
return {
passthroughFileCopy: true,
}
}