-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
115 lines (100 loc) · 2.76 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const CleanCSS = require('clean-css');
const Image = require('@11ty/eleventy-img');
const embedYouTube = require('eleventy-plugin-youtube-embed');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const pluginRss = require('@11ty/eleventy-plugin-rss');
const footnotes = require('eleventy-plugin-footnotes');
module.exports = function (eleventyConfig) {
// The file types that eleventy will look at and copy into _output/
eleventyConfig.setTemplateFormats([
// Templates:
'html',
'njk',
'md',
// Static Assets:
'css',
'jpeg',
'jpg',
'png',
'svg',
'woff',
'woff2',
'txt'
]);
// Copy all files in static/ into _output/, regardless of file extension
eleventyConfig.addPassthroughCopy('_pages/static');
// Used for merging tags from the base layout with the tags from each individual post
eleventyConfig.setDataDeepMerge(true);
// Used for minifying and inlining CSS
eleventyConfig.addFilter('cssmin', function (code) {
return new CleanCSS({}).minify(code).styles;
});
// Resizes and compresses images
eleventyConfig.addNunjucksAsyncShortcode(
'image',
async function imageShortcode(src, alt, sizes) {
let metadata = await Image(src, {
widths: [640],
formats: ['webp'],
urlPath: '/static/',
outputDir: './_output/static/'
});
let imageAttributes = {
alt,
sizes,
loading: 'lazy',
decoding: 'async'
};
return Image.generateHTML(metadata, imageAttributes);
}
);
// Lazy-load YouTube videos
eleventyConfig.addPlugin(embedYouTube, {
lite: {
css: {
path: '/static/lite-yt-embed.css'
},
js: {
path: '/static/lite-yt-embed.js'
}
}
});
// Syntax highlighting for code-blocks
eleventyConfig.addPlugin(syntaxHighlight);
// Convert string to date
eleventyConfig.addFilter('date', function (dateStr) {
return new Date(dateStr);
});
// Pretty-print date
eleventyConfig.addFilter('formatDate', function (date) {
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
});
// Pretty-print date and time
eleventyConfig.addFilter('formatDateTime', function (date) {
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
timeZoneName: 'short'
});
});
// RSS (Atom) Feed
eleventyConfig.addPlugin(pluginRss);
// Footnotes
eleventyConfig.addPlugin(footnotes);
return {
// Enables the use of shortcodes within Markdown
markdownTemplateEngine: 'njk',
dir: {
input: '_pages',
includes: '../_includes',
output: '_output'
}
};
};