-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
99 lines (83 loc) · 2.75 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
88
89
90
91
92
93
94
95
96
97
98
99
const { emojify } = require('node-emoji');
const assert = require('assert');
const parseJSON = require('date-fns/parseJSON');
const format = require('date-fns/format');
const {
responsiveImage,
instagramImage,
websiteScreenshot,
} = require('./plugins/images');
const markdownIt = require('markdown-it');
const hljs = require('highlight.js');
if (!process.env.NETLIFY) {
require('dotenv').config();
}
if (!process.env.SKIP_IMAGES) {
assert(
process.env.SCREENSHOT_TOKEN,
'You forgot to set the SCREENSHOT_TOKEN environment variable!'
);
}
module.exports = (eleventyConfig) => {
eleventyConfig.addPassthroughCopy('src/static');
eleventyConfig.addPassthroughCopy('src/**/_redirects');
eleventyConfig.addPlugin(require('eleventy-plugin-svg-contents'));
eleventyConfig.addPlugin(require('@11ty/eleventy-plugin-rss'));
eleventyConfig.addFilter('jsmin', (code) => {
const babel = require('@babel/core');
try {
const result = babel.transformSync(code, {
presets: [
'@babel/preset-env',
...(process.env.ELEVENTY_ENV === 'prod' ? ['minify'] : []),
],
plugins: ['@babel/plugin-proposal-class-properties'],
});
return result.code;
} catch (ex) {
console.error(ex);
return code;
}
});
eleventyConfig.addFilter('parseInt', parseInt);
eleventyConfig.addFilter('parseDate', parseJSON);
eleventyConfig.addFilter('formatDate', format);
eleventyConfig.addFilter('firstLine', (str) => str.split('\n')[0]);
eleventyConfig.addFilter('emojify', emojify);
eleventyConfig.addFilter('limit', function (list, n) {
return list.slice(0, n);
});
const GITHUB_EMOJI_REGEX = /^\w*:[a-z_]+:/;
eleventyConfig.addFilter('removeEmoji', function (commit) {
const match = GITHUB_EMOJI_REGEX.exec(commit);
return match ? commit.replace(match, '') : commit;
});
eleventyConfig.addFilter('getEmoji', function (commit) {
const match = GITHUB_EMOJI_REGEX.exec(commit);
return match ? match[0] : '';
});
eleventyConfig.addNunjucksAsyncShortcode('responsiveImage', responsiveImage);
eleventyConfig.addNunjucksAsyncShortcode(
'websiteScreenshot',
websiteScreenshot
);
eleventyConfig.addNunjucksAsyncShortcode('instagramImage', instagramImage);
const md = markdownIt({
linkify: true,
html: true,
highlight: function (str, lang) {
return `<pre class="hljs"><code>${
lang && hljs.getLanguage(lang)
? hljs.highlight(lang, str, true).value
: md.utils.escapeHtml(str)
}</code></pre>`;
},
});
eleventyConfig.setLibrary('md', md);
return {
dir: {
input: './src',
output: './_site',
},
};
};